通过参考SOF's Question的回答,我想修复一下,在页面加载后(在用户的个人资料页面上)自动选择选项值传递到目标字段。
我还有兴趣知道文本字段上的更改方法在失去焦点之前被触发。
$(function () {
$("#options").change(function () {
setTarget(); // Something has changed so lets rebuild the target
});
$("#options2").change(function () {
setTarget(); // Something has changed so lets rebuild the target
});
});
// Just get the values you want and update the target
function setTarget() {
var tmp = $("#options").val();
tmp += $("#options2").val();
$('#targetTextField').val(tmp);
}
答案 0 :(得分:0)
要在页面加载时传递所选的选项值,请在$
函数中使用此事件:
$(function () {
...
// Add it here
setTarget();
});
对于传输到值的文本字段的更改,请使用keyup
事件而不是change
:
$(function () {
...
$("#options3").keyup(function () {
setTarget(); // Text has changed
});
...
});