0

このスクリプトが原因で、「予期しないトークン <」が発生し続けます。

<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 タグを追加してみたり、文字の代わりにエンティティ名を使用してみたり、document.write 内に空白がないことを確認したりしました。なぜ機能しないのですか? document.write は HTML エンティティをサポートしていると思いましたか?

EDIT :=演算子をに変更しました==。一重引用符も追加しましたが、Blogger に送信したときに XML エラーが発生しました。私はまだ「予期しないトークン」<エラーが発生しています...

更新スクリプトをこれに更新しましたが、まったく同じエラーが発生します。

<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>
4

2 に答える 2

4

少なくとも、文字列を一重引用符で囲む必要があります...

<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-02T20:12:38.430 に答える