且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery问题从脚本标签获取文本?

更新时间:2023-12-05 07:51:04

.html()可能会给您带来更多的运气,如果这样不起作用,请尝试this.innerHtml.但是,我没有对此进行测试.

You might have more luck with .html() and if that doesn't work try this.innerHtml. I did not test this however.

不过,我确实为您的代码提供了另一条提示.如果只需要类型代码的脚本,则可以有一个选择器,而不必在循环中检查属性:

I do have another tip for your code however. If you want only scripts of type code you can have a single selector instead of having to check the attribute in the loop:

$("script[type=code]").each(function() {
    alert($(this).html());
    alert(this.innerHtml);
});