<select id="paymenttype">
<option value="">---Select---</option>
<option>100</option>
<option>200</option>
<option>300</option>
<option>400</option>
<option>500</option>
</select>
<input type="text" id="check" value="" readonly/>
<input type="text" id="update" value="" />
JS
$("#paymenttype").change(function(){
$("#check").val($('#paymenttype option:selected').text());
});
$("#check").change(function(){
alert("soul");
$("#update").val(0);
});
jsfield代码示例
如代码$("#check").change(function()
所示,它不工作?我应该使用什么功能,以Jquery的工作?当输入文本框中有变化时,我要添加什么?这只是一个例子
您只需要在设置值时手动触发更改事件:
$("#paymenttype").change(function(){
$("#check").val($('#paymenttype option:selected').text()).change(); // <-- HERE
});
http://jsfiddle.net/infernalbadger/e6yEd/7/你可以添加一个小插件,这样你就可以在一个调用中设置值并同时触发change事件。
这样你只需调用$("#check").changeVal($('#paymenttype option:selected').text());
:
(function($) {
$.fn.changeVal = function(value) {
return this.val(value).change();
};
})(jQuery);
http://jsfiddle.net/infernalbadger/e6yEd/11/尝试添加触发器
$("#paymenttype").change(function(){
$("#check").val($('#paymenttype option:selected').text()).change();
});
注意第二行末尾的.change()
使用trigger function运行change() handler on '#check'http://jsfiddle.net/fliptheweb/e6yEd/8/