[英]Textfield is not allowing me to enter characters on keypress in Firefox
我有一種形式,當我通過按下所有其他瀏覽器來輸入字符時,它允許用戶這樣做。 但是,當我使用Firefox時,它不允許用戶通過按鍵輸入字符,但允許用戶復制和粘貼。 這是我的腳本如下:
<script language="javascript">
function aaa(){
document.getElementById('txtwebref').style.color = 'black';
}
</script>
<input name="txtwebref" type="text" id="txtwebref" size="50" value="Insert reference number" style="width:350px; height:50px; border:1px solid #000; border-radius:15px; text-align:center;color:#CCC; font-family:Arial, Helvetica, sans-serif; font-size:24px;" onkeypress="if ( isNaN(this.value + String.fromCharCode(event.keyCode) )) return false;" onfocus="blank(this);" onblur="unblank(this)" onclick="aaa();"/>
window.event
不是標准的JavaScript。
太“ DOM方式”,將一個功能分配給onkeypress
屬性。 它的第一個參數將是一個Event對象。
像這樣:
<input name="txtwebref" type="text" id="txtwebref" size="50" value="Insert reference number" style="width:350px; height:50px; border:1px solid #000; border-radius:15px; text-align:center;color:#CCC; font-family:Arial, Helvetica, sans-serif; font-size:24px;" onfocus="blank(this);" onblur="unblank(this)" onclick="aaa();"/>
<script type="text/javascript">
document.getElementById('txtwebref').onkeypress = function checkMe(ev) {
return !isNaN(this.value + String.fromCharCode(ev.keyCode) );
}
</script>
你需要
onkeypress="return !isNaN(this.value + String.fromCharCode(event.charCode))"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.