我遇到了奇怪的问题。当用户更改表单上的复选框输入元素时,会产生足够的事件编程更改。我应该如何面对这个挑战?下面的代码:如何在javascript中处理输入元素状态的编程式更改
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js"></script>
<script type="text/javascript">
jQuery(document).ready(
function() {
jQuery("#cb").change(
function() {
alert("Changed!");
return true;
}
);
jQuery("#b").click(
function() {
var newState = !jQuery("#cb").attr('checked');
jQuery("#cb").attr('checked', newState);
});
});
</script>
</head>
<body>
<form action="#">
<p>
<input type="button" id="b" />
<input type="checkbox" id="cb" />
</p>
</form>
</body>
</html>
更新 我不控制元素的变化,我只需要处理它们。这是我写的通用计划代码。
在问题和标签中没有提到jQuery。 – Alternatex 2015-10-16 11:53:13