简体   繁体   English

用jQuery .html插入javascript

[英]Inserting javascript with jQuery .html

I'm experiencing an issue with a website I'm working on, where I originally believed I could simply replace $("main").html(this) which was originally code for a flash object, with a new and improved HTML5/Javascript version. 我正在使用的网站遇到问题,我本来以为我可以用新的经过改进的HTML5 /替换原来为Flash对象编写的$("main").html(this) JavaScript版本。

The original code: 原始代码:

$("#main").html('<div style="height: 100%; width: 100%; overflow: hidden;"><object width="100%" height="100%" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000">\
                    <param value="images/uploads/'+image_id+'.swf" name="movie">\
                    <param value="true" name="allowFullScreen">\
                    <param value="#737373" name="bgcolor">\
                    <param value="" name="FlashVars">\
                    <embed width="100%" height="100%" flashvars="" bgcolor="#737373" allowfullscreen="true" src="images/uploads/'+image_id+'.swf" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">\
                    </object></div>\
                ');
            });

And my (failed) attempt at inserting my new code: 我(失败)尝试插入我的新代码:

$("#main").html('<script type="text/javascript">pano=new pano2vrPlayer("container");skin=new pano2vrSkin(pano);pano.readConfigUrl("xml/tablet_'+image_id+'.xml");hideUrlBar();</script>');

It doesn't even work when I just put , so I know it's gotta be the javascript itself. 我什至放不下它甚至不起作用,所以我知道它必须是javascript本身。

I've looked at the solutions out there, but I can't make sense in how to properly implement them here in the most efficient way. 我已经看过那里的解决方案,但是对于如何以最有效的方式在此处正确实施它们却没有任何意义。

Your help is much appreciated, thanks! 非常感谢您的帮助,谢谢!

You can put your script in a external file and do something like this: 您可以将脚本放入外部文件中,然后执行以下操作:

var scrpt = document.createElement("script");
scrpt.type = "text/javascript";
scrpt.src = "js/yourImprovedFile.js";
// Use any selector
$("#main").append(scrpt);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM