开发者

Object.Watch with disabled attribute

<html>
<head>
<script type="text/javascript">
window.onload = function() {
 var btn = document.getElementById("button");
 var tog = document.getElementById("toggle");
 tog.onclick = function() {
  if(btn.disabled) {
   btn.disabled = false;
  } else {
   btn.disabled = true;
  }
 };
 //btn.watch("disabled", function(prop, val, newval) { });
};
</script>
</head>
<body>
<input type="button" value="Button" id="button" />
<input type="button" value="Toggle" id="toggle" />
</body>
</html>

If you test this code, the Tog开发者_如何学Pythongle button will successfully enable and disable the other button.

However, un-commenting the btn.watch() line will somehow always set the disabled tag to true.

Any ideas?


Because monitor function defined by watch must return new value:

 btn.watch("disabled", function(prop, val, newval) { return newval; });

EDIT: I assume you want define your monitor method without affecting the functionality of your script. That's why you have to take care of returning new value for disabled property.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜