gpt4 book ai didi

javascript - 如何用JavaScript提取多个脚本标签之间的代码块?

转载 作者:行者123 更新时间:2023-11-30 13:34:09 29 4
gpt4 key购买 nike

<分区>

我有以下函数,它通过 AJAX 从 URI 拉入 Javascript block 执行它:

function loadViewViaAjax(url, callbackOnSuccess) {
Ext.Ajax.request({
url: url,
success: function(objServerResponse) {
var responseText = objServerResponse.responseText;
var scripts, scriptsFinder=/<script[^>]*>([\s\S]+)<\/script>/gi;
while(scripts=scriptsFinder.exec(responseText)) {
eval.call(window,scripts[1]);
}
if(typeof callbackOnSuccess != 'undefined') {
callbackOnSuccess.call();
}
}
});
}

例如,它提取这段文本,并执行 SCRIPT 标签之间的所有操作:

<script type="text/javascript">
clearExtjsComponent(targetRegion);
var start_info_panel = new Ext.Panel({
padding: 10,
style: "margin: 10px",
width: 300,
html: '<h1>Html Item 1</h1>'
});
replaceComponentContent(targetRegion, start_info_panel);
</script>

如何更改 loadViewViaAjax 函数,以便它执行多个脚本标记之间的所有内容?例如:

<script type="text/javascript">
clearExtjsComponent(targetRegion);
var start_info_panel = new Ext.Panel({
padding: 10,
style: "margin: 10px",
width: 300,
html: '<h1>Html Item 1</h1>'
});
replaceComponentContent(targetRegion, start_info_panel);
</script>
<script type="text/javascript">
clearExtjsComponent(targetRegion_help);
var help_panel = new Ext.Panel({
padding: 10,
style: "margin: 10px",
width: 300,
html: '<p>This is the help text.</p>'
});
replaceComponentContent(targetRegion_help, help_panel);
</script>

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com