English 中文(简体)
• 如何做以下工作?
原标题:How to make the following jQuery snippet work?
  • 时间:2009-09-06 06:15:28
  •  标签:
var func = function()
{
    $(this).hide();
    $parent = $(this).parent();
    $parent.removeClass( my_signature_mouseover );
    var text = $(this).val();
    var $span = $("#status span");
    $span.text(text);
    $span.show();
};
$("#status input").keyup(function (e) {
    var keyCode = e.keyCode || e.which;
    if (keyCode == 13) {
       func();
    }
}).blur(func);

I want to make func run if blur or pressing "Enter" on it. But the above code works only when blur, in the case of pressing "Enter",it reports "Permission denied to access parentNode".

虽然我知道与<条码>这一条有关的一些内容,但在不同的背景下,这几条关键词是: 我不知道如何确定。

最佳回答
问题回答

为此:

var func = function(elem)
{
    elem.hide();
    var $parent = elem.parent();
    $parent.removeClass( my_signature_mouseover );
    var text = elem.val();
    var $span = $("#status span");
    $span.text(text);
    $span.show();
};
$("#status input").keyup(function (e) {
    var keyCode = e.keyCode || e.which;
    if (keyCode == 13) {
       func($(this));
    }
}).blur(function () {
    func($(this));
});




相关问题