由于这个脚本,我一直得到“意外令牌”:
<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>我不明白它为什么要抛出那个错误。我已经研究了大约两个小时了。我试着添加CDATA标签,我尝试使用实体名称而不是字符,我确保在document.write中没有空格等等,为什么不能工作呢?我以为document.write支持HTML?
编辑:我将=操作符更改为==。我还添加了单引号,但当我向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>发布于 2013-09-02 20:12:38
至少你得在你的字符串上加上一个单引号.
<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>发布于 2013-09-02 20:17:30
试试这个:
<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>");
}
});
https://stackoverflow.com/questions/18580130
复制相似问题