简体   繁体   English

如何从同一页面上的Ajax加载内容访问javascript函数?

[英]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.

相关问题 如何使用AJAX加载的内容中的javascript? - How do I use javascript from content loaded with AJAX? 从ajax加载的脚本访问JavaScript函数 - Access JavaScript functions from scripts loaded from ajax 使用Ajax将内容加载到div中...如何将加载新页面的div定位到同一div? - Loading content into div with Ajax … How do I target the same div with the new page loaded? 如何在同一工厂的不同javascript函数中访问变量? - how can i access variables in different javascript functions on the same factory? 如何在ajax加载的页面中使用MVC的功能? - How do I use functions of the MVC in a page loaded by ajax? 从Javascript文件加载另一个脚本,但无法访问已加载脚本中的函数 - Loading another script from a Javascript file but I can't access functions in the loaded script 如何在JavaScript的同一页面上显示文本内容? - How can I display text content on the same page in JavaScript? 如何从Javascript同步运行Ajax函数? - How can I run Ajax functions synchronously from Javascript? 如何通过AJAX调用知道何时将所有内容加载到页面上? - How to know when all content is loaded on the page from AJAX call? 我有一个使用ajax调用在另一个页面的div标签中加载的html页面,我想在加载的页面上触发javascript函数吗? - I have a html page that loaded in div tag in another page using ajax call I want to trigger javascript functions on loaded page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM