【问题标题】:Chaining .live() events to functions将 .live() 事件链接到函数
【发布时间】:2023-03-28 05:55:02
【问题描述】:

我无法集中精力使用当前值进行更新。这段代码中是否存在错误,或者我是否缺少更简洁的方法?我可以传递“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();
    }
}

【问题讨论】:

  • 您实际上在哪里定义 focused?我在任何地方都没有看到var focused = false;
  • 看看第二个代码块.. ooo。你的意思是var focused = '';?是的,就是这样......
  • 嗯...我在任何地方都没有看到var focused = '';

标签: jquery function click live chain


【解决方案1】:

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

var focused = false;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-30
    相关资源
    最近更新 更多