</script> 标记位置错误
</script> tag in wrong place
我不知道为什么我的网络浏览器 returns "SyntaxError: Unexpected EOF" 在我的网站上出现错误。我没有做任何更改,但由于昨天同一个网站工作正常,所以必须更改一些内容。
这是我的源代码(直接来自 FTP 服务器):
<script type="">
$(function(){
$("body").append("<div class='tooltip2_showv' id='tooltip2_show'></div>");
$('a.button.notactive').mousemove(function(e){
$('#tooltip2_show').html( $('.popup',$(this)).html());
$('#tooltip2_show').show();
$('#tooltip2_show').css({'top': e.pageY + 5, left: e.pageX + 5,'position': 'absolute'});
}).mouseout(function(){
$('#tooltip2_show').hide();
});
});
</script>
看起来不错,但从网络浏览器 (Web Inspector) 检查相同的代码:
<script type="">
$(function(){
$("body").append("<div class='tooltip2_showv' id='tooltip2_show'></script></div>");
$('a.button.notactive').mousemove(function(e){
$('#tooltip2_show').html( $('.popup',$(this)).html());
$('#tooltip2_show').show();
$('#tooltip2_show').css({'top': e.pageY + 5, left: e.pageX + 5,'position': 'absolute'});
}).mouseout(function(){
$('#tooltip2_show').hide();
});
});
脚本标记的结尾位置错误!你知道为什么吗?
这不是唯一错误放置的 "end of script" 标签。
复活节快乐 ;)
您不能在脚本中包含 </div>
之类的内容。对于解析器,这意味着脚本已经结束。所以它包括一个自动 </script>
因为这是正确的做法!
解决方案:不要将 </div>
放入脚本中。写入 <\/div>
.
哦,去掉type=""
,这是错误的。
编辑:只要从附加方法 http://jsfiddle.net/byadd1m3/ 中取出 </script>
,您的代码就可以正常工作。我更喜欢的是创建元素并将其存储在变量中。使用新的 div 定义一个变量,稍后将该变量附加到正文。像这样:
$(function () {
var newDiv = "<div class='tooltip2_showv' id='tooltip2_show'></div>";
$("body").append(newDiv);
$('a.button.notactive').mousemove(function (e) {
$('#tooltip2_show').html($('.popup', $(this)).html());
$('#tooltip2_show').show();
$('#tooltip2_show').css({
'top': e.pageY + 5,
left: e.pageX + 5,
'position': 'absolute'
});
}).mouseout(function () {
$('#tooltip2_show').hide();
});
});
为什么您的代码不起作用:
$("body").append("<div class='tooltip2_showv' id='tooltip2_show'>
</script></div>");//What is script doing here?
我不知道为什么我的网络浏览器 returns "SyntaxError: Unexpected EOF" 在我的网站上出现错误。我没有做任何更改,但由于昨天同一个网站工作正常,所以必须更改一些内容。
这是我的源代码(直接来自 FTP 服务器):
<script type="">
$(function(){
$("body").append("<div class='tooltip2_showv' id='tooltip2_show'></div>");
$('a.button.notactive').mousemove(function(e){
$('#tooltip2_show').html( $('.popup',$(this)).html());
$('#tooltip2_show').show();
$('#tooltip2_show').css({'top': e.pageY + 5, left: e.pageX + 5,'position': 'absolute'});
}).mouseout(function(){
$('#tooltip2_show').hide();
});
});
</script>
看起来不错,但从网络浏览器 (Web Inspector) 检查相同的代码:
<script type="">
$(function(){
$("body").append("<div class='tooltip2_showv' id='tooltip2_show'></script></div>");
$('a.button.notactive').mousemove(function(e){
$('#tooltip2_show').html( $('.popup',$(this)).html());
$('#tooltip2_show').show();
$('#tooltip2_show').css({'top': e.pageY + 5, left: e.pageX + 5,'position': 'absolute'});
}).mouseout(function(){
$('#tooltip2_show').hide();
});
});
脚本标记的结尾位置错误!你知道为什么吗? 这不是唯一错误放置的 "end of script" 标签。
复活节快乐 ;)
您不能在脚本中包含 </div>
之类的内容。对于解析器,这意味着脚本已经结束。所以它包括一个自动 </script>
因为这是正确的做法!
解决方案:不要将 </div>
放入脚本中。写入 <\/div>
.
哦,去掉type=""
,这是错误的。
编辑:只要从附加方法 http://jsfiddle.net/byadd1m3/ 中取出 </script>
,您的代码就可以正常工作。我更喜欢的是创建元素并将其存储在变量中。使用新的 div 定义一个变量,稍后将该变量附加到正文。像这样:
$(function () {
var newDiv = "<div class='tooltip2_showv' id='tooltip2_show'></div>";
$("body").append(newDiv);
$('a.button.notactive').mousemove(function (e) {
$('#tooltip2_show').html($('.popup', $(this)).html());
$('#tooltip2_show').show();
$('#tooltip2_show').css({
'top': e.pageY + 5,
left: e.pageX + 5,
'position': 'absolute'
});
}).mouseout(function () {
$('#tooltip2_show').hide();
});
});
为什么您的代码不起作用:
$("body").append("<div class='tooltip2_showv' id='tooltip2_show'>
</script></div>");//What is script doing here?