$? 用的jQuery?。我扣了一段jQuery代码:

// Argument "data" should be string of html

// context (optional): If specified, the fragment will be created in this context,

// defaults to document

// keepScripts (optional): If true, will include scripts passed in the html string

jQuery.parseHTML = function( data, context, keepScripts ) {

if ( typeof data !== "string" ) {

return [];

}

if ( typeof context === "boolean" ) {

keepScripts = context;

context = false;

}

var base, parsed, scripts;

if ( !context ) {

// Stop scripts or inline event handlers from being executed immediately

// by using document.implementation

if ( support.createHTMLDocument ) {

context = document.implementation.createHTMLDocument( "" );

// Set the base href for the created document

// so any parsed elements with URLs

// are based on the document's URL (gh-2965)

base = context.createElement( "base" );

base.href = document.location.href;

context.head.appendChild( base );

} else {

context = document;

}

}

parsed = rsingleTag.exec( data );

scripts = !keepScripts && [];

// Single tag

if ( parsed ) {

return [ context.createElement( parsed[ 1 ] ) ];

}

parsed = buildFragment( [ data ], context, scripts );

if ( scripts && scripts.length ) {

jQuery( scripts ).remove();

}

return jQuery.merge( [], parsed.childNodes );

};

jQuery在把string转化为HTML时,默认是会去除script标签的。 所以,没有执行JS脚本

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐