Javascript 用jQuery组织多个嵌入代码
我的网站上有几个嵌入代码,例如: 嵌入代码#1: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
嵌入代码#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>