简体   繁体   English

在主页或子页面的MVC3中使用javascript

[英]Using javascript in MVC3, in master or child page

I'm building a web application using MVC3 and I'm wondering what the etiquette is in regards to having javascript (whether it's embedded or external) in the master page, and then having javascript that pertains to an individual child page. 我正在使用MVC3构建一个Web应用程序,我想知道礼仪是关于在母版页中使用javascript(无论是嵌入式还是外部式),然后使用与个别子页面相关的javascript。

For example, is it fine to have an embedded section for javascript in the maser page, and then another one in the child page, such that there will be two sets of tags when the page is rendered in the browser? 例如,在maser页面中有一个javascript的嵌入部分,然后在子页面中有另一个部分,这样在浏览器中呈现页面时会有两组标记吗?

What is the generally accepted way to do this? 普遍接受的方法是什么? Thank you. 谢谢。

That is acceptable. 这是可以接受的。 There's no problem. 这里没有问题。

The alternative way to execute javascript code that runs on only 1 page would be to add javascript code within your master .js file, and, on each page load, check 执行仅在1页上运行的javascript代码的替代方法是在master .js文件中添加javascript代码,并在每个页面加载时检查

if (this.href == "http://.............") 
{ 
    /* execute unique js */ 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM