我有一个以html格式加载文章的应用。对于一些文章,我在JQuery中有一个带滑块的图库。
我将JQuery和滑块JS文件添加到应用程序并加载它们,但滑块仍然不起作用。
从REST服务收到的HTML:
<div id="gallery">
<div class="royalSlider">
<img src="xxx">
<img src="xxx">
<img src="xxx">
<img src="xxx">
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#gallery .royalSlider').royalSlider({
autoScaleSlider: true,
imageScaleMode: 'fill',
...,
});
});
</script>
<div id="content">
<span id="header>This is the title</span>
<p>This is the content</p>
</div>
HTML只是添加到面板的HTML配置字段中。
知道如何让这个滑块与ST2配合使用吗?
答案 0 :(得分:0)
我在将HTML内容加载并添加到面板后,通过创建以下函数解决了我的问题:
executeJSScript: function(panel) {
var scripts = panel.renderElement.dom.getElementsByTagName("script");
for(var i=0; i < scripts.length; i++) {
eval(scripts[i].text);
}
}
它获取面板dom中的所有标签,而不是执行(eval函数)每个脚本。
确实不是很优雅,但它有效...希望它可以帮助某人,如果你有更好的解决方案,请分享!