开发者

javascript tab key problem? in textbox

开发者 https://www.devze.com 2023-03-02 19:46 出处:网络
Why doesnt work this code one safari,chrome and internet explorer.. Only works with Opera and Firefox...

Why doesnt work this code one safari,chrome and internet explorer.. Only works with Opera and Firefox...

  $("#txtAd").keypress(function (e) {


    var code = e.keyCode || e.which;
    if (code == 9) {

        $("#txtSoyad").val(开发者_高级运维'');

    };

});


jQuery abstracts that so you don't have to :)

To determine which character was entered, examine the event object that is passed to the handler function. While browsers use differing properties to store this information, jQuery normalizes the .which property so you can reliably use it to retrieve the character code.

Source.

Use e.which, no need to use || short circuit evaluation trick.

Though in saying that, your code did work for me in Chrome 10.

Are you sure $("#txtSoyad") is a valid selector, and has selected what you want? Output the length property, if you don't see 1, it isn't selecting it correctly.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号