我使用jQuery来了解输入的变化。
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#id_back_ground_color").change(function(){
alert("hello");
});
$("#salam").click(function(){
alert("hey");
$("#id_back_ground_color").val('changed!');
});
});
</script>
</head>
<body>
<input id="id_back_ground_color" type="text">
<button id="salam" >
</body>
</html>
当我点击按钮时,我得到一个&#34;嘿&#34;警惕,但我没有得到#34;你好&#34;警报。为什么呢?
答案 0 :(得分:0)
按钮上的点击与id_back_ground_color
字段中的修改之间没有任何关联。
更改事件在其值更改时发送到元素。这个 事件仅限于元素,盒子和 元素。对于选择框,复选框和单选按钮,事件 当用户使用鼠标进行选择时立即触发, 但对于其他元素类型,事件将延迟到 元素失去焦点。
答案 1 :(得分:0)
更改此行
$("#id_back_ground_color").val('changed!');
到这个
$("#id_back_ground_color").val('changed!').trigger( "change" );