应该在哪里使用jQuery code脚本块放置在一个ASP.NET MVC母版页? [英] Where should a script block with jquery code be placed on an ASP.NET MVC Master Page?

查看:96
本文介绍了应该在哪里使用jQuery code脚本块放置在一个ASP.NET MVC母版页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开始使用jQuery和有麻烦的hello world类型的例子去为asp.net的MVC。我得到一个运行时错误预期目标,试图与此脚本加载页面时。

一个。应该在哪里脚本标签被放置在一个母版页?
B.什么可能我是做错了什么?肯定有我的页面a元素?

 < SCRIPT SRC =../脚本/ jQuery的-1.2.6.min.js类型=文/ JavaScript的>< / SCRIPT>            < SCRIPT SRC =../脚本/ jquery.corner.js类型=文/ JavaScript的>< / SCRIPT>            <脚本类型=文/ JavaScript的>
                $(文件)。就绪(函数(){
                    $(A)。点击(函数(事件){
                        警报(感谢您访问!);
                    });
                });
            < / SCRIPT>


解决方案

B)我检查了快速的测试页面上内嵌脚本,它使用的作品好了,我的意见的火狐萤火插件安装用于查找问题:


  • 在Firebug的脚本选项卡使用监视窗口右侧插入,并检查你的脚本的一部分,看看做他们回来了。

  • 我想用把 $ 在监视窗口,并检查它是否认定为函数()开始:也许jQuery是不是propertly链接

  • 然后把 $(A)在监视窗口,并检查它是否返回集具有正确的号码
    对应于选择在一组项目的

  • 保持运行脚本的部分,直到你遇到什么问题

Getting started with jquery and having trouble getting hello world type example going for asp.net mvc. I get a runtime error "object expected" when trying to load a page with this script.

A. Where should script tags be placed in a master page? B. What might I be doing wrong? There are definitely "a" elements in my page?

<script src="../Scripts/jquery-1.2.6.min.js" type="text/javascript"></script>

            <script src="../Scripts/jquery.corner.js" type="text/javascript"></script>

            <script type="text/javascript">
                $(document).ready(function() {
                    $("a").click(function(event) {
                        alert("Thanks for visiting!");
                    });
                });
            </script>

解决方案

B) I checked your inline script on quick test page and it works ok, so i advice using Firefox with FireBug plugin installed for finding the problem:

  • In Firebug's "script" tab use the Watch window on the right to insert and check parts of your script and see what do they return.
  • I'd start with putting $ in watch window and checking if it's recognized as function(): perhaps jQuery is not linked propertly
  • Then put $("a") in watch window and check if the set it returns has correct number of items corresponding to "a" selector in a set
  • Keep running parts of script until you encounter something wrong

这篇关于应该在哪里使用jQuery code脚本块放置在一个ASP.NET MVC母版页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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