2015-03-02 99 views
0

這是我的代碼... 在這一個文本框是隱藏的,另一個是啓用命名(許可證).. 雖然檢查複選框的複選框的值需要設置到隱藏文本框,並啓用它... 並啓用文本需要被禁用...如何將一個文本框設置爲啓用而另一個文本框被禁用?

$(document).ready(function(){ 
 
    
 
    $('input[name=licence3]').blur(function(){ 
 
    var third = $(this).val(); 
 
    var first = $('input[name=licence1]').val(); 
 
    var second = $('input[name=licence2]').val(); 
 
    
 
    
 
    
 
    $('input[name=licence]').val(first+second+third); 
 
    
 
    }); 
 
    
 
    $("#check").click(function() { 
 
    $('input[name=licence1]').val(""); 
 
    $('input[name=licence2]').val(""); 
 
    $('input[name=licence3]').val(""); 
 
    $('input[name=licence]').val(""); 
 
    
 
    // Here i need another coding While clicking checkbox 
 
//the checkbox value should set to the hidden textbox value which is in same name... 
 
    //And the Enabled textbox should be disable 
 
    }); 
 
    
 
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> 
 
<form> 
 
    <input type="hidden" name="licence" value="" disabled="disabled" /> 
 
    <input type="text" name="licence1" value="" /> 
 
    <input type="text" name="licence2" value="" /> 
 
    <input type="text" name="licence3" value="" /> 
 
    
 
    <input type="checkbox" id="check" value="Applied"> 
 
    <br> 
 
    <br> 
 
    Final<input type="text" name="licence" value="" /> 
 
</form>

回答

0
$('input:checkbox').on('click',function(){ 
    if(this.checked){ 
     var value = $('input[name=licence1]').val()+$('input[name=licence2]').val()+$('input[name=licence3]').val(); 
     $('input:hidden').val(this.val(value)).prop('disabled',!this.checked); 
     $('input:enabled').val('').prop('disabled',this.checked); 
    } 
}); 

我couldnot能夠完全明白你的問題,我認爲,當複選框被選中,你需要4件事

  1. 設置複選框的值爲輸入:隱藏字段。
  2. 禁用所有啓用的輸入字段。
  3. 清空已啓用的輸入值。
  4. 顯示隱藏的輸入字段值等於總結了3個輸入字段
+0

很抱歉的麻煩。 ..名爲(許可證)的文本框只能禁用和啓用相同的命名文本框...將複選框值分配到隱藏文本框字段 – Kevin 2015-03-02 13:55:29

+0

檢查我注意到的上述4件事情。希望它有幫助 – 2015-03-02 13:57:21

+0

它的工作......謝謝 – Kevin 2015-03-02 14:15:38

0

可以使用禁止輸入標籤

$('input[name=licence]').attr('disabled', 'true') 

Coudn't瞭解您的實際需求,希望下面的代碼片段有助於

$(document).ready(function(){ 
 
    
 
    $('input[name=licence3]').blur(function(){ 
 
    var third = $(this).val(); 
 
    var first = $('input[name=licence1]').val(); 
 
    var second = $('input[name=licence2]').val(); 
 
    
 
    
 
    
 
    $('input[name=licence]').val(first+second+third); 
 
     $('input[name=licence]').attr('disabled','true') 
 
    }); 
 
    
 
    $("#check").click(function() { 
 
    $('input[name=licence1]').val(""); 
 
    $('input[name=licence2]').val(""); 
 
    $('input[name=licence3]').val(""); 
 
    $('input[name=licence]').val(""); 
 
    
 
    // Here i need another coding While clicking checkbox 
 
//the checkbox value should set to the hidden textbox value which is in same name... 
 
    //And the Enabled textbox should be disable 
 
    }); 
 
    
 
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> 
 
<form> 
 
    <input type="hidden" name="licence" value="" disabled="disabled" /> 
 
    <input type="text" name="licence1" value="" /> 
 
    <input type="text" name="licence2" value="" /> 
 
    <input type="text" name="licence3" value="" /> 
 
    
 
    <input type="checkbox" id="check" value="Applied"> 
 
    <br> 
 
    <br> 
 
    Final<input type="text" name="licence" value="" /> 
 
</form>

+0

謝謝你的...但隱藏的文本框應顯示並啓用,也讓這三個文本框值 – Kevin 2015-03-02 13:51:15

相關問題