我会将多个字段的值传递给一个文本字段。有问题,复选框。如果用户选中复选框,如何确保复选框(允许)仅将值传递给文本字段?
HTML:
<select id="Salary_para1">
<option value="">Choose...</option>
<option value="MYR" selected>MYR</option>
<option value="SGD" >SGD</option>
</select>
<input id="Salary_value" type="text"/>
+ <input type="checkbox" id="Salary_para2" name="Salary_para2" value=" + Allowance" />Allowance<br/>
<input type="text" id="targetTextField" name="targetTextField" size="31" tabindex="0" maxlength="99" value="">
代码:
$(function() {
$("#Salary_para1").change(function(){
setTarget()
});
$("#Salary_para2").change(function(){
setTarget()
});
$("#Salary_value").keyup(function(){
setTarget();
});
});
function setTarget(){
var tmp = $("#Salary_para1").val();
tmp += $("#Salary_value").val();
tmp += $("#Salary_para2").val();
$('#targetTextField').val(tmp);
}