我有一个包含一些HTML和很多Javascript的div
<div id="mydiv">
<p>Hello Philippines</p> my first time in Philippines is nice
<script type="text/javascript">alert("how was it became nice?");</script>
well I experienced a lot of things
<script type="text/javascript">alert("and how about your Japan's trip?");</script>
well its more nicer ^^ but both countries are good! hahah
</div>
我想将非Javascript代码和Javascript代码放在两个单独的变量中:
var html = $("#mydiv").html();
我的问题是我的javascript正在执行,这使我停止创建我想要的代码,即将javascript和非javascript存储到两个不同的变量。
注意:我需要存储的javascript以便以后执行
答案 0 :(得分:2)
您可以使用code
代码而不是script
:
HTML:
<div id="mydiv">
<p>Hello Philippines</p> my first time in Philippines is nice</p>
<code>alert("how was it became nice?");</code>
well i experienced a lot of things
<code>alert("and how about your Japan's trip?");</code>
<p>well its more nicer ^^ but both countries are good! hahah
</p>
</div>
JS:
var html = $('#mydiv *').not('code').html()
var code = $('#mydiv code').text()