Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 用jQuery组织多个嵌入代码_Javascript_Jquery_Embed_Organized - Fatal编程技术网

Javascript 用jQuery组织多个嵌入代码

Javascript 用jQuery组织多个嵌入代码,javascript,jquery,embed,organized,Javascript,Jquery,Embed,Organized,我的网站上有几个嵌入代码,例如: 嵌入代码#1: 嵌入代码#2: _qoptions={ qacct:“p-3asdb5E0g6” }; 等等 如何组织它们并将它们分离到一个外部js文件中以保持标记干净 谢谢你的帮助 我不认为jQuery有多大帮助 我要么直接编写它们,要么将它们存储在xml文件中 对于document.write,它将是这样的(noscript将被删除,因为在js文件中没有任何意义) // --- starts jsfile var embeds = [ '<ob

我的网站上有几个嵌入代码,例如:

嵌入代码#1:


嵌入代码#2:


_qoptions={
qacct:“p-3asdb5E0g6”
};
等等

如何组织它们并将它们分离到一个外部js文件中以保持标记干净


谢谢你的帮助

我不认为jQuery有多大帮助 我要么直接编写它们,要么将它们存储在xml文件中

对于document.write,它将是这样的(noscript将被删除,因为在js文件中没有任何意义)

// --- starts jsfile
var embeds = [
'<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/f8Lp2ssd5A9ErAc&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/f8Lp2A9ErAc&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>',

'<script type="text/javascript">_qoptions={qacct:"p-3asdb5E0g6"};</script><script type="text/javascript" src="http://edge.quantserve.com/quant.js"></script>'
]; // notice the lack of comma on the last embed
function putEmbed(idx) {
  document.write(embeds[idx]);
}
// ------ end ------
/---启动jsfile
var嵌入=[
'',
“qoptions={qacct:“p-3asdb5E0g6”};”
];//注意最后一次嵌入时缺少逗号
函数putEmbed(idx){
文件编写(嵌入[idx]);
}
//----结束------
然后使用

<script type="text/javascript">
putEmbed(0); // youtube
</script>

putEmbed(0);//youtube
后来

<script type="text/javascript">
putEmbed(1); // quant
</script>

putEmbed(1);//数量
<script type="text/javascript">
putEmbed(0); // youtube
</script>
<script type="text/javascript">
putEmbed(1); // quant
</script>