Home > Web Front-end > JS Tutorial > body text

javascript在子页面中函数无法调试问题解决方法_javascript技巧

WBOY
Release: 2016-05-16 17:03:16
Original
761 people have browsed it

近期在做一个项目,会遇到在子页面中提交的时候会无法能够调试javascript代码的情况出现,有时候这种问题,我们无法正常在浏览器,看到我们子页面的javascript代码,所以只能够用原始的alert 或者 console.log(),当然,这也是一种解决方法,但是有时候,我们就想看一下程序到底是如何运行的,同时也可以看每个参数到底是什么值,所以意义还是比较大的。

我贴张图,大家就大概了解是什么时候会出现这个问题了。

复制代码 代码如下:



这个其实是函数声明,大家如果了解javascript上下文的话,就知道其实函数声明只是在页面上下文加载的时候加载的函数名,其函数内容无法正常加载。

如果我们换成函数自执行或者是在函数自治性中定义这个函数声明的话,那么就可以解决这个问题了。
复制代码 代码如下:

(function(){
function stopWatchDog(watchDogId) {
alert("aa");
var url = '';
var params = {
watchDogId : watchDogId,
};
$.post(url, params, function(data) {
if (data.success) {
closeDialog();
tbGrid.send();
} else {
if (data.errorMsg != null && data.errorMsg != "") {
jAlert(data.errorMsg, "系统消息");
} else {
jAlert("停止异常", "系统消息");
}
$("#saveBtn").removeAttr("disabled");
$("#saveBtn").css("color", "white");
}
}, "json");
}
})();
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!