12

ヘッド内に新しいメタ タグを挿入しようとしています。ヘッド内で編集できないコンテンツ管理システムを使用しているため、jQuery を使用してこれを実行しようとしています。残念ながら、私はそれを働かせることができません。

これは、次の Web ページに追加したコードです: http://www.newcastlegateshead.com

<script type="text/javascript"> 
$("head").append("<meta name=viewport content=width=400, initial-scale=0.45, minimum-    scale=0.45/><link rel=apple-touch-icon href=/images/customIcon.png/><meta name=apple-mobile-web-app-capable content=no /><meta name=apple-mobile-web-app-status-bar-style content=black-translucent /><link rel=apple-touch-icon-precomposed href=/images/customIcon.png/> ");
</script>
4

2 に答える 2

17

内でコードを試してください

<script type="text/javascript"> 
     $(document).ready(function() {
         $("head").append("<meta name=viewport content=width=400, initial-scale=0.45, minimum-    scale=0.45/><link rel=apple-touch-icon href=/images/customIcon.png/><meta name=apple-mobile-web-app-capable content=no /><meta name=apple-mobile-web-app-status-bar-style content=black-translucent /><link rel=apple-touch-icon-precomposed href=/images/customIcon.png/> ");
    });
</script>

の短縮形$(document).ready(function() {...})は次のとおりです。

jQuery(function ($) {
    // Your code
})

これにより、コードが実行中に確実に実行されonloadます。

于 2012-06-13T15:50:53.680 に答える