[英]How can i access javascript functions from ajax loaded content on the same page?
1) on main page i have javascript function 1)在主页上,我有JavaScript功能
function editSuccess(data) { alert("editSuccess called"); 函数editSuccess(data){alert(“被称为editSuccess”); }
}
2) From main page I load some content into div using ajax then i need call javascript function from loaded content but it's don't see editSuccess function 2)从主页上,我使用ajax将某些内容加载到div中,然后我需要从加载的内容中调用javascript函数,但是看不到editSuccess函数
This should work as long as editSuccess
is available in the global scope. 只要
editSuccess
在全局范围内可用, editSuccess
应该起作用。 Remember that JavaScript has function scope, so if you define editSuccess
inside a function, it will only be available within that function. 请记住,JavaScript具有函数作用域,因此,如果您在函数内部定义
editSuccess
,它将仅在该函数内可用。 Consider this example: 考虑以下示例:
// javascript
window.onload = function() {
function editSuccess() {
alert("Hello");
}
};
// html
<div onclick='editSuccess()'>..</div>
// or
<script>editSuccess()</script>
will not work since editSuccess
does not exist in the global scope. 由于
editSuccess
在全局范围内不存在,因此将不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.