亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

輸入字段不能輸入其他字符

輸入字段不能輸入其他字符

絕地無雙 2022-10-13 10:40:16
我可以知道是什么錯誤導致我的輸入字段無法輸入字符嗎?因為在輸入字段中設置></\":*?|了這些符號限制后,其他字符無法在輸入字段中輸入。<!DOCTYPE html><html><body><h1>Can't type character in the input field</h1><input type="text" class="form-control blank" id="function_code" name="function_code" title="function_code" onpaste="return false"><div id="error-box"></div></body></html><script>function showError (key) {  var errBox = document.querySelector("#error-box");  errBox.textContent = "The character " + key.toString() + " is not allowed!";  //Dismiss the error  window.setTimeout(function () {      errBox.textContent = "";  }, 10000)}document.getElementById("function_code").onkeypress = function(e) {var chr = String.fromCharCode(e.which);if ("></\":*?|".indexOf(chr) >= 0)  showError(chr)  return false;};</script>希望有人能幫我解決這個問題。謝謝。
查看完整描述

2 回答

?
人到中年有點甜

TA貢獻1895條經驗 獲得超7個贊

if ("></\":*?|".indexOf(chr) >= 0){

  showError(chr)

   return false;

}

return true // !!!

<!DOCTYPE html>

<html>

<body>


<h1>Can't type character in the input field</h1>



<input type="text" class="form-control blank" id="function_code" name="function_code" title="function_code" onpaste="return false">

<div id="error-box"></div>


</body>

</html>


<script>


function showError (key) {

  var errBox = document.querySelector("#error-box");

  errBox.textContent = "The character " + key.toString() + " is not allowed!";

  //Dismiss the error

  window.setTimeout(function () {

      errBox.textContent = "";

  }, 10000)

}



document.getElementById("function_code").onkeypress = function(e) {

var chr = String.fromCharCode(e.which);


if ("></\":*?|".indexOf(chr) >= 0){

  showError(chr)

   return false;

}

return true

};

</script>


查看完整回答
反對 回復 2022-10-13
?
隔江千里

TA貢獻1906條經驗 獲得超10個贊

只需刪除 return false; 或將其更改為 true


如果您返回 false,則不會輸入任何內容


<!DOCTYPE html>

<html>

<body>


<h1>Can't type character in the input field</h1>



<input type="text" class="form-control blank" id="function_code" name="function_code" title="function_code" onpaste="return false">

<div id="error-box"></div>


</body>

</html>


<script>


function showError (key) {

  var errBox = document.querySelector("#error-box");

  errBox.textContent = "The character " + key.toString() + " is not allowed!";

  //Dismiss the error

  window.setTimeout(function () {

      errBox.textContent = "";

  }, 10000)

}



document.getElementById("function_code").onkeypress = function(e) {

var chr = String.fromCharCode(e.which);


if ("></\":*?|".indexOf(chr) >= 0)

  showError(chr)

};

</script>


查看完整回答
反對 回復 2022-10-13
  • 2 回答
  • 0 關注
  • 107 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號