注册 登录
编程论坛 JavaScript论坛

Jquery 重设Input的 onkeypress 事件失败如何处理??

kira007 发布于 2010-07-02 13:54, 1385 次点击
默认为 不可输入
<input type="text" value=""  onkeypress="return false;"/>
通过以下代码改写 onkeypress ,但经测试失败。
(无论LabelValue等不等 其它硬件,$("#HD"+Rows+"_9") 这个 input 文本均能输入)
请问这是什么原因???
if(LabelValue =="其它硬件")
    {

                $("#HD"+Rows+"_9").attr("onkeypress","return true;");
                alert("设置可写")        
    }
    else
    {
                $("#HD"+Rows+"_9").attr("onkeypress","return false;");
                alert("设置不可写")
    }
   
4 回复
#2
poyexyp2010-07-02 17:45
keypress是事件,不是属性。
#3
graybobo2010-07-13 15:49
楼上正解
试试这样写:

$("#HD"+Rows+"_9").keypress(
    function(){
        return true;
    }
)
#4
Johnsylm2010-08-02 22:23
改成 keydown 事件吧 。
别用 attr ,用 #3 的方法 。但是事件改为 keydown
#5
gulimeksoft2010-08-05 17:31
设为不可用就可以啦$("#HD"+Rows+"_9").attr("disabled",false);
1