【发布时间】:2021-08-09 09:19:00
【问题描述】:
这里有一些简单的代码,当 div 标签文本发生变化时,应该触发警报:
<!DOCTYPE html>
<html>
<body>
<p>Modify the text by clicking on it, then click outside the field to fire the onchange event.</p>
<div type="text" name="txt" value="" onchange="myFunction(this.value)" contenteditable="true">Change Value by clicking here</div>
<script>
function myFunction(val) {
alert("The input value has changed. The new value is: " + val);
}
</script>
</body>
</html>
不使用事件监听器可以做到这一点吗?
【问题讨论】:
-
试试this
标签: javascript html jquery css dom