愚蠢的转义引号问题
我知道这应该是基本的,但对于我的一生......
eventMouseover: function(calEvent, domEvent) {
if (typeof calEvent.id != 'undefined'){
var layer = "<div id='events-layer' class='fc-transparent' style='position:absolute; width:100%; height:100%; top:-1px; text-align:right; z-index:100'> <a> <img border='0' style='padding-right:5px;' src='/icon_note_delete.png' width='16' onClick='deleteEvent("+calEvent.id+");'></a></div>";
$(this).append(layer);
}
}
不起作用的部分是
onClick='deleteEvent("+calEvent.id+");
因为 id 将是一个字符串而不是数字,我需要引用它。
它给了我
onClick="deleteEvent(e_1984_2_184_668)"
,但我需要
onClick="deleteEvent('e_1984_2_184_668')"
我已经尝试过
onClick='deleteEvent(\'"+calEvent.id+"\');
,但它也不起作用。我知道这是我所缺少的愚蠢的东西,但非常感谢您的帮助!
I know this should be basic but for the life of me....
eventMouseover: function(calEvent, domEvent) {
if (typeof calEvent.id != 'undefined'){
var layer = "<div id='events-layer' class='fc-transparent' style='position:absolute; width:100%; height:100%; top:-1px; text-align:right; z-index:100'> <a> <img border='0' style='padding-right:5px;' src='/icon_note_delete.png' width='16' onClick='deleteEvent("+calEvent.id+");'></a></div>";
$(this).append(layer);
}
}
The part that isn't working is
onClick='deleteEvent("+calEvent.id+");
Since the id will be a string not a number I need to quote it.
as is it is giving me
onClick="deleteEvent(e_1984_2_184_668)"
but I need
onClick="deleteEvent('e_1984_2_184_668')"
I have tried
onClick='deleteEvent(\'"+calEvent.id+"\');
but it didn't work either. I know this is something stupid that I am missing but help is much appriecated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您应该使用双引号将
calEvent.id
括起来,因为它位于单引号字符串内:但是,在我看来,如果您使用一系列 jQuery 调用来创建您的HTML 改为:
You should use double-quotes to surround
calEvent.id
, because it's within a single quote string:However, it would be easier and more readable in my opinion if you used a chain of jQuery calls to create your HTML instead:
尝试一下:
Try that:
翻转单引号和双引号可能会更容易(JSFiddle):
然后你可以转义单引号,生成的 HTML 字符串看起来更像是您在日常标记中看到的 HTML(属性值用双引号,JavaScript 中用单引号)。
It might be easier to flip the single and double quotes around (JSFiddle):
Then you can escape the single quotes, and the resulting HTML string looks more like that HTML you would see in everyday markup (double-quotes around attribute values, single-quotes in the JavaScript).
看来你正在使用 jQuery。我建议使用 jQuery 创建元素:
其中
someClass
和someOtherClass
为:It seems you are using jQuery. I suggest to create the elements with jQuery:
where
someClass
andsomeOtherClass
would be: