如何避免运行母版页面的javascript文件? [英] How can I avoid to run a master page javascript file?

查看:40
本文介绍了如何避免运行母版页面的javascript文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我有一个带有javascript函数的内容页面,而且主页面有一个javascript文件,但是,对于这个函数和内容页面,我想忽略那个javascript文件,避免运行它,只使用我的内容页面的javascript函数,是
还有什么办法吗?谢谢!

Hello, I have a content page with a javascript function, and the master page has a javascript file, however, for this function and content page, I want to ignore that javascript file, avoid to run it, to use only my content page javascript function, is there any way to do it? thanks!

推荐答案

这是因为函数名称相同吗?如果是这样,您应该使用技术来命名您的JavaScript代码。实际上,你应该总是使用技术命名你的javascript。

Is this because the functions are the same name? If so you should use techniques to namespace your javascript code. Actually, you should always use techniques to namespace your javascript.

<!DOCTYPE html>
<head></head>
<body>

<button onclick="yourdomain.yourobject.sayIt();">Click Me</button>

<!-- this would probably be in a separate file -->
<script>

//root of your namespace is "yourdomain"
var yourdomain = yourdomain || {};

//within the namespace you can create "objects"
yourdomain.yourobject = function () {
	
	//add functions to the object
	this.saySomething = function () {
        alert('Hello');
    }
	
	//return an anonymous object with references to the functions
	return {
		sayIt : saySomething
	};    
}();

</script>
</body>
</html>


这篇关于如何避免运行母版页面的javascript文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆