繁体   English   中英

内部.live()内的jQuery .select()不适用于IE7和IE8

[英]jQuery .select() inside .live() does not work on IE7 and IE8

jQuery(document).ready(function($) {
    $('input[type="text"]').live('focus', function() {
        if (this.value == 'someValue') {
            this.select();
        }
    });
});

与.delegate()和.on()相同的结果。

我错过了什么?

任何帮助表示赞赏,谢谢!

使用.on对我来说.on 也许您希望它在您单击时选择文本?

$("form").on("click", ":text", function(){
    if ( $(this).val() === "someValue" ) {
        $(this).select();
    }
});​

小提琴: http//jsfiddle.net/jonathansampson/nfKm7/

它确实有效,只要在使用focus事件时选择了文本,它就会被取消选择

使用on()focus以外的事件似乎更好

看到这个小提琴

演示: http//jsfiddle.net/hjgZ3/

function($)删除$ function($)

<input type="text" value="someValue" />  

       $(function(){
          $('input[type="text"]').live('focus', function() {
                if (this.value == 'someValue') {
                   alert('hi');                
                   //this.select();
                }
            });
        })

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM