Coffeescript jQuery 设置数据()
我做错了什么?我试图将 .data() 分配给每个锚点。现在,该脚本仅删除标题,但不在 data() 中存储任何内容。当我尝试 console.log(title)
时,它写得很好,但仍然没有存储它。我正在使用 jQuery 1.7.1
我在咖啡中有以下几行
$(document).ready ->
initBubble();
initBubble = ->
$('a[title]').each (index, element) =>
setInfoAttr($(element))
setInfoAttr = (element) ->
title = element.attr('title')
element.data('info', title).removeAttr('title')
编译后的输出如下
(function() {
var initBubble, setInfoAttr;
$(document).ready(function() {
return initBubble();
});
initBubble = function() {
var _this = this;
return $('a[title]').each(function(index, element) {
return setInfoAttr($(element));
});
};
setInfoAttr = function(element) {
var title;
title = element.attr('title');
return element.data('info', title).removeAttr('title');
};
}).call(this);
What am I doing wrong? I am trying to assign .data() to each anchor. Now, the script only removes the title, but doesn't store anything in data(). When I tried console.log(title)
it wrote the title fine, but still didn't store it. I'm using jQuery 1.7.1
I have the following lines in coffee
$(document).ready ->
initBubble();
initBubble = ->
$('a[title]').each (index, element) =>
setInfoAttr($(element))
setInfoAttr = (element) ->
title = element.attr('title')
element.data('info', title).removeAttr('title')
The compiled output is as follows
(function() {
var initBubble, setInfoAttr;
$(document).ready(function() {
return initBubble();
});
initBubble = function() {
var _this = this;
return $('a[title]').each(function(index, element) {
return setInfoAttr($(element));
});
};
setInfoAttr = function(element) {
var title;
title = element.attr('title');
return element.data('info', title).removeAttr('title');
};
}).call(this);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许稍微把事情打乱一下。我唯一能看到的是 initBubble 函数在调用时可能是未定义的。
Maybe shuffle things around a little bit. Only thing I can see is that the initBubble function may be undefined when it is called.