错误:语法错误:错误的令牌< [英] Error: Uncaught SyntaxError: Unexpected token <
问题描述
由于某种原因,我收到此错误消息:
For some reason, I'm getting this error message:
Uncaught SyntaxError: Unexpected token <
对于这一行代码:
title: '<img src="/images/text/text_mario_planet_jukebox.png" id="text_mario_planet_jukebox"/>',
在这种情况下:
$(document).ready(function() {
$('#infobutton').click(function() {
$('#music_descrip').dialog('open');
});
$('#music_descrip').dialog({
title: '<img src="/images/text/text_mario_planet_jukebox.png" id="text_mario_planet_jukebox"/>',
autoOpen: false,
height: 375,
width: 500,
modal: true,
resizable: false,
buttons: {
'Without Music': function() {
$(this).dialog('close');
$.cookie('autoPlay', 'no', { expires: 365 * 10 });
},
'With Music': function() {
$(this).dialog('close');
$.cookie('autoPlay', 'yes', { expires: 365 * 10 });
}
}
});
});
我认为一切都应该顺利进行,但是我不明白为什么<
会以某种方式将其抛弃.
I think everything should be good to go, but I don't understand why the <
is somehow throwing this off..
哎呀,忘了显示这是怎么回事!我不好,
whoops, forgot to show where this is happening! My bad,
http://www.marioplanet.com/index.asp
有什么想法吗?
推荐答案
这是浏览器问题,而不是javascript或JQuery问题;试图将尖括号解释为HTML标签.
This is a browser issue rather than a javascript or JQuery issue; it's attempting to interpret the angle bracket as an HTML tag.
在设置javascript时尝试执行以下操作:
Try doing this when setting up your javascripts:
<script>
//<![CDATA[
// insert teh codez
//]]>
</script>
或者,将您的JavaScript移至单独的文件.
Alternatively, move your javascript to a separate file.
啊..我已经找到了那个链接.我所说的根本不是问题. 这是个问题,已从网站上删除:
Ahh.. with that link I've tracked it down. What I said was the issue wasn't the issue at all. this is the issue, stripped from the website:
<script type="text/javascript"
$(document).ready(function() {
$('#infobutton').click(function() {
$('#music_descrip').dialog('open');
});
$('#music_descrip').dialog({
title: '<img src="/images/text/text_mario_planet_jukebox.png" id="text_mario_planet_jukebox"/>',
autoOpen: false,
height: 375,
width: 500,
modal: true,
resizable: false,
buttons: {
'Without Music': function() {
$(this).dialog('close');
$.cookie('autoPlay', 'no', { expires: 365 * 10 });
},
'With Music': function() {
$(this).dialog('close');
$.cookie('autoPlay', 'yes', { expires: 365 * 10 });
}
}
});
});
您能发现错误吗?它在第一行:<script
标记未关闭.它应该是
<script type="text/javascript">
Can you spot the error? It's in the first line: the <script
tag isn't closed. It should be
<script type="text/javascript">
但是,我以前的建议仍然成立:您应该将带有标签的脚本包含在CDATA块中,或将它们移动到单独链接的文件中.
My previous suggestion still stands, however: you should enclose intra-tagged scripts in a CDATA block, or move them to a separately linked file.
这不是这里的问题,但是它可以更快地显示出真正的问题.
That wasn't the issue here, but it would have shown the real issue faster.
这篇关于错误:语法错误:错误的令牌<的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!