在我的網站我用下面的代碼:如何在所有的頁面禁用鍵除了文本框
<script type='text/javascript'>
document.onkeydown = function (e)
{
return false;
}
</script>
<script type='text/javascript'>
document.onkeyup = function (e)
{
return false;
}
</script>
我的網站上標題,不過,我希望用戶只能夠輸入聊天文本框和其他地方。聊天文本框的代碼是:
<div style="-moz-user-select: none; -webkit-user-select: none; -ms-user-
select:none; user-select:none;-o-user-select:none;" unselectable="on"
onselectstart="return false;" onmousedown="return false;">
<script type='text/javascript'>
document.onkeydown = function (e)
{
return true;
}
</script>
<script type='text/javascript'>
document.onkeyup = function (e)
{
return true;
}
</script>
<script type="text/javascript" async> ;
(function(o,l,a,r,k,y)
{if(o.olark)return;
r="script";y=l.createElement(r);r=l.getElementsByTagName(r)[0];
y.async=1;y.src="//"+a;r.parentNode.insertBefore(y,r); y=o.olark=function()
{k.s.push(arguments);k.t.push(+new Date)}; y.extend=function(i,j)
{y("extend",i,j)}; y.identify=function(i){y("identify",k.i=i)};
y.configure=function(i,j){y("configure",i,j);k.c[i]=j}; k=y._={s:[],t:[+new
Date],c:{},l:a}; })(window,document,"static.olark.com/jsclient/loader.js");
/* custom configuration goes here (www.olark.com/documentation) */
olark.identify('2624-366-10-5413');
</script>
<script type='text/javascript'>
document.onkeydown = function (e) {
return false;
}
</script>
<script type='text/javascript'>
document.onkeyup = function (e)
{
return false;
}
</script>
這是我迄今爲止編寫的完整代碼。
你是什麼意思*無處*?你不希望他們使用頁面上的其他輸入字段嗎?如果是這樣,爲什麼他們在那裏呢?如果你不能刪除它們,你不能僅僅禁用它們嗎? – BSMP
@BSMP我希望他們在任何地方都被禁用,但在聊天中。 – antimalwareprogram
@javamaster是的,我不明白你的意思。爲什麼頁面上還有其他輸入字段,如果它們不被使用。請不要說你的輸入樣式是你的頁面。 – Darkrum