我在点击按钮时调用一个函数.但是这个功能没有被调用.我不知道我做错了什么.请帮忙.
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
function clear() {
document.getElementById('inp').value = "";
}
</script>
</head>
<body>
<input type="text" id="inp" name="">
<input type="button" onclick="clear()">
</body>
</html>Run Code Online (Sandbox Code Playgroud)
clear不是保留字,而是它的呼唤document.clear.尝试更新功能名称
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
function clear1() {
document.getElementById('inp').value = "";
}
</script>
</head>
<body>
<input type="text" id="inp" name="">
<input type="button" onclick="clear1()">
</body>
</html>Run Code Online (Sandbox Code Playgroud)
注意:覆盖document/window/prototype函数是一种不好的做法.这仅用于演示目的.
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
function clear1() {
document.getElementById('inp').value = "";
}
document.clear = function(){
console.log('My clear function')
}
</script>
</head>
<body>
<input type="text" id="inp" name="">
<input type="button" onclick="clear()">
</body>
</html>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
58 次 |
| 最近记录: |