buildIMG = (src, resize) ->
html = '<div class="left"><div class="foods_image">'
html += '<a onclick="popitup("http://somewhere.com/test" href="javascript:void(0)">'
html += ' <img src="'+src+'" '+resize+' />'
html += '</a>'
html += '</div></div>'
html
popitup = (url) ->
newwindow=window.open(url,'name','height=640,width=640')
newwindow.focus() if window.focus
false
我目前有一个书签小程序,可以将JavaScript代码(如上所示)插入到网站中。我编写了上述CoffeeScript代码,并生成了以下内容:
(function() {
var buildIMG, popitup;
buildIMG = function(src, resize) {
var html, nbsp;
html = '<div class="left"><div class="foods_image">';
html += '<a onclick="popitup(\'http://somewhere.com/test\');" href="javascript:void(0)">';
html += ' <img src="' + src + '" ' + resize + ' />';
html += '</a>';
html += '</div></div>';
return html;
};
popitup = function(url) {
var newwindow;
newwindow = window.open(url, 'name', 'height=640,width=640');
return newwindow.focus()(window.focus ? false : void 0);
};
}).call(this);
我剪掉了使用buildIMG的函数。该函数在网站上创建一个覆盖层,并在该覆盖层中显示所有图像。对于每个图像,都会调用buildIMG来创建html。
问题在于
onclick="popitup("http://somewhere.com/test"
部分不起作用。它未定义。我做的一个解决方案是移除由CoffeeScript生成的代码:
(function() {
}).call(this);
只要我删除了它,问题就立即解决了。那么我如何才能让CoffeeScript不在我生成的JavaScript代码中添加那些行?
this
。 - user395760