Object.Watch with disabled attribute
-
13-10-2019 - |
문제
<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 Toggle 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.
제휴하지 않습니다 StackOverflow