触发 onchange
属性事件当元素的值改变时。
没有。
<element onchange="script or Javascript function name">
<input type="checkbox">, <input type="file">, <input type="password">, <input type="radio">, <input type="range">, <input type="search">, <input type="text">, <keygen>, <select> <textarea>
onchange |
Yes | Yes | Yes | Yes | Yes |
<!DOCTYPE html>
<html>
<body>
<select id="mySelect" onchange="myFunction()">
<option value="CSS">CSS</option>
<option value="HTML">HTML</option>
<option value="Javascript">Javascript</option>
<option value="SQL">SQL</option>
</select>
<script>
function myFunction() {
alert(document.getElementById("mySelect").value);
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
Enter some text:
<input type="text" name="txt" value="Hello" onchange="myFunction(this.value)">
<input type="text" name="txt2" value="Hello another" onchange="myFunction(this.value)">
<script>
function myFunction(val) {
alert(val);
}
</script>
<p>Edit text and tab out.</p>
</body>
</html>