将.live()事件链接到函数

时间:2011-06-29 17:53:19

标签: jquery function click live chain

我无法专注于使用当前值进行更新。这段代码中是否有错误,或者我是否缺少更清洁的方法?我可以通过'this'或'event'吗?

我收到此错误:

'focused is not defined'

我有这段代码:

$("input, select, textarea, button, .link, div, .button").live({
  click:clearDefault,
  focusin:function() {focused = ($(this).attr('title'))},
  focusout:function() {focused = false},
  mouseover:onHelp,
  mouseout:helpFallback
});

映射到这些功能:

function onHelp() {
if (!helpDiv) {
    helpDiv = $('#helpText');
}
var $this = $(this);
var text = $this.attr('title');
if ($this.attr('titlehtml')) {
    var text = $this.attr('titlehtml');
}
if ($this.hasClass('screenshot')) {
    text += "<img src='images/icon_table_" + $this.attr('id') + ".png' >";
}
if ($this.attr('errorhtml')) {
    text += "<div id='userError'>"+$this.attr('errorhtml')+"</div>";
}
helpDiv.show().html(text);
}

function helpFallback() {
    if (focused) {
        helpDiv.show().html(focused);
    } else {
        helpDiv.hide();
    }
}

1 个答案:

答案 0 :(得分:0)

定义如下焦点并设置一些默认值

var focused = false;