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

发布于 2024-11-17 21:43:07 字数 1033 浏览 9 评论 0原文

我无法专注于更新当前值。这段代码中是否存在错误,或者我是否缺少更清晰的方法?我可以传递“这个”或“事件”吗?

我收到此错误:

'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();
    }
}

I cannot get focused to update with the current value. Is there a bug in this code or is there a cleaner approach I am missing? Can I pass 'this' or the 'event'?

I am getting this error:

'focused is not defined'

I have this block of code:

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

Which maps to these functions:

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();
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

童话里做英雄 2024-11-24 21:43:07

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

var focused = false;

Define focused as below and set some default value

var focused = false;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文