我有一个php
页面,里面有很多html
和javascript
代码。我其他页面使用ajax
将 id 发送到第一页并获取结果并将其放入 div 元素内。
现在我想运行那些包含 javascript
和 html
代码的返回代码。
应该怎么做?
这是我对第一页的 ajax 请求:
$(document).ready(function() {
$.ajax({
type: "POST",
url: "showing.php",
data: "s_id="+s_id+"&submit=true",
success: function(msg){
str=$.trim(msg)
document.getElementById('tabs-2').innerHTML = str;
document.getElementById("ui-id-2").click();
}
})
最佳答案
我认为事件委托(delegate)可以解决您的问题。
如下:
使用$.on()。您不是在元素上注册事件,而是在不会被删除的父级上注册
例如:
$('#tabs-2').on('click', '#ui-id-2', function(){
//do something
})
关于javascript - 如何运行通过ajax进程包含的javascript代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27752959/