将 .live() 事件链接到函数
我无法专注于更新当前值。这段代码中是否存在错误,或者我是否缺少更清晰的方法?我可以传递“这个”或“事件”吗?
我收到此错误:
'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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如下定义聚焦并设置一些默认值
Define focused as below and set some default value