意外的标记<来自样式标记
Unexpected token < From a Style Tag
因为这个脚本,我一直得到"意外的令牌<":
<script type='text/javascript'>
$(document).ready(function(){
if (window.location.pathname + window.location.search = '/search/?q=label:Web-Design|label:Graphic-Design|label:Identity-Design|label:Brand-Design') {
document.write (<style type="text/css">#HTML25, #HTML23, #HTML22, #HTML24 { display:block; }</style>);
}
});
</script>
我不明白它为什么会犯那个错误。我已经研究了大约2个小时了。我试着添加CDATA标记,我试着使用实体名而不是字符,我确保文档.write中没有空白,等等。为什么它不起作用?我认为document.write支持HTML实体?
EDIT:我将=
运算符更改为==
。我还添加了单引号,但当我提交给Blogger时,我得到了XML错误:"元素的内容必须由格式良好的字符数据或标记组成",所以我将HTML字符改为HTML名称并重新提交。我仍然得到"意外代币"<错误
UPDATE我已经更新了脚本,但仍然得到了完全相同的错误:
<script type='text/javascript'>
<![CDATA[
$(document).ready(function(){
if ((window.location.pathname + window.location.search) === '/search/?q=label:Web-Design|label:Graphic-Design|label:Identity-Design|label:Brand-Design') {
document.write ('<style type="text/css">#HTML25, #HTML23, #HTML22, #HTML24 { display:block; }</style>');
}
});
]]>
</script>
至少您必须在字符串周围添加一个引号。。。
<script type='text/javascript'>
$(document).ready(function () {
if ((window.location.pathname + window.location.search) === '/search/?q=label:Web-Design|label:Graphic-Design|label:Identity-Design|label:Brand-Design') {
// add the style to your head
$('head').append(String.fromCharCode(60) + 'style type="text/css">#HTML25, #HTML23, #HTML22, #HTML24 { display:block; }' + String.fromCharCode(60) + '/style>');
// or decide to individually show the divs with jquery selectors
$('div#HTML25').css('display', 'block');
}
});
</script>
试试这个:
<script type='text/javascript'>
$(document).ready(function(){
if (window.location.pathname + window.location.search == '/search/?q=label:Web-Design|label:Graphic-Design|label:Identity-Design|label:Brand-Design') {
document.write("<style type='text/css'>#HTML25, #HTML23, #HTML22, #HTML24 { display:block; }</style>");
}
});
相关文章:
- 当包含另一个asp文件时,是否也包含所有引用的样式和脚本页面
- 将样式表插入iframe
- 跟踪在页面加载时应用内联样式的JavaScript
- 分析高度属性时出现意外值{{specs.height}}.index.html
- 如果文本字段为空,则使用JavaScript应用CSS样式
- 铬:“;未捕获的语法错误:意外的标记:"
- 定义完全独立的样式信息
- Javascript未捕获语法错误意外的标识符错误
- W3C循环样式的JavaScript
- jQuery/JavaScript在线公文包表单-打印样式表
- 使用递归、Ramda.js和无点样式重构字符串的getPermutations()
- 未捕获的语法错误:意外的标记{
- FF和Chromium中CSS样式按钮的外观差异
- "未捕获的语法错误:意外的标记}"
- 如何首先设置样式<td>表中包含在窗体中的元素
- 将样式应用于融合表上的图标时,会得到意外的标识符
- 意外的标记<来自样式标记
- Html5拖放意外激活了css:悬停样式
- Node.js-样式没有't应用于页面&谷歌Chrome表示:未捕获语法错误:意外的令牌<
- React.js内联样式的Radium出现意外标记错误