在IE7和IE8上,live()中的jQuery .select()无法正常工作

olhwl3o2  于 2022-11-22  发布在  jQuery
关注(0)|答案(3)|浏览(132)
jQuery(document).ready(function($) {
    $('input[type="text"]').live('focus', function() {
        if (this.value == 'someValue') {
            this.select();
        }
    });
});

中 的 每 一 个
.delegate().on() 的 结果 相同 。
我 错过 了 什么 ?
任何 帮助 都 是 感激 不尽 的 。

uqjltbpv

uqjltbpv1#

使用.on对我来说很好用。也许你想让它在你点击的时候选择文本?

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

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

nbysray5

nbysray52#

它确实起作用了,当使用focus事件时,文本一旦被选中,就会被取消选中
使用on()focus以外的事件似乎效果更好
see this fiddle

nzkunb0c

nzkunb0c3#

演示 : http://jsfiddle.net/hjgZ3/
function($) 中 删除 $

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

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

中 的 每 一 个

相关问题