gpt4 book ai didi

Javascript:禁用文本字段不起作用

转载 作者:行者123 更新时间:2023-11-30 07:54:51 24 4
gpt4 key购买 nike

我已经尝试为表单编写一些 javascript,当用户输入某个单词时,下面的文本字段将自动禁用。问题是,当我尝试 jsfiddle 中的代码时,代码将运行顺利,但是当我在我的中使用它时项目,它不起作用。谁能解释我的代码有什么问题。

<script>
function matchWord(e){
if(document.getElementById('uname').value.trim === 'Unknown' || document.getElementById('uname').value.trim === 'unknown'){
document.getElementById('pword').disabled = true;
document.getElementById('response').disabled = true;
alert('you enter bannned name in the field');
}
else{
}
}
document.getElementById('uname').onkeyup = matchWord();
</script>

<html>
<body>
Name:<input type="text" name="uname" id="uname" placeholder="Username"><br>
password:<input type="password" name='pword' id='pword' placeholder="password"><br>
Responsibility:<select id = "response">
<option>---Responsibility---</option>
</select>
</body>
</html>

最佳答案

问题一:错别字matchword(),替换为matchWord();

问题2:trim是一个方法!请改用 document.getElementById('uname').value.trim()

function matchWord(e) {
if (document.getElementById('uname').value.trim() === 'Unknown' || document.getElementById('uname').value.trim() === 'unknown') {
document.getElementById('pword').disabled = true;
document.getElementById('response').disabled = true;
alert('you enter bannned name in the field');
}
}
Name:
<input type="text" name="uname" id="uname" placeholder="Username" onkeyup="matchWord()">
<br> password:
<input type="password" name='pword' id='pword' placeholder="password">
<br> Responsibility:
<select id="response">
<option>---Responsibility---</option>
</select>

关于Javascript:禁用文本字段不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42664963/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com