2

我想防止输入焦点 onclick 和焦点输入双击。

就像是....

$('input').click(function) {
    $(this)preventFocus();
});

$('input').dblclick(function) {
    $(this)focus();
});

或者也许我应该使用 if 语句?

4

2 回答 2

5

我想这样的事情应该有效:

$('input').on({
    focus: function() {
        if (!$(this).data('disabled')) this.blur()
    },
    dblclick: function() {
        $(this).data('disabled', true);
        this.focus()
    },
    blur: function() {
        $(this).data('disabled', false);
    }
});

小提琴

于 2013-10-30T20:46:31.270 回答
1

您可以尝试以下内容

HTML:

<input type="text" id="myInput" readonly="readonly" />

jQuery:

$("#myInput").dblclick(function(){
   $(this).prop("readonly", false)
});
$("#myInput").blur(function(){
   $(this).prop("readonly", true); 
});

http://jsfiddle.net/KWuR5/

于 2013-10-30T20:51:20.423 回答