热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ASP.NET开发者使用jQuery应该了解的几件事情

如果你是有着APS.NET开发背景的人员,那么jQuery的几个概念建议你应该忘掉。像使用其它的framework一样,你应该学习一下jQuery的所有语法等约定来让它更好的为你服务。

下面这几点希望能够帮你加快你的学习。

1.把selectors当作asp.net中的sets。

   在asp.net的世界,通过一个查询找到一系列控件是非常少见的.相反我们比较习惯于通过一个唯一的ID来找到一个控件。当然,在jQuery中这个也是没有问题的,但是jQuery的选择功能相对更加神奇。

   使用jQuery的selectors能够很容易定位到一个set的元素,相对来说比在asp.net中使用迭代的规则来找到一个set的元素更加清晰和易于表达。

2.使用CSS类来代替styling。

   另外一个不直观的技术是把CSS类作为一个flag。与'selector engin'一样,'flag'类也是个令人惊喜的东西。

   举个例子来说吧,最近有个活动是做一个在线的能够与客户端互动的纸牌游戏。一个需求是纸牌需要有个onclick haddler在某个特定时间,不过这些事件只针对那些face down(脸朝下)的。作为一个.net的开发者我立刻能够想到的办法是让这些纸牌在客户端通过一个collection来编号.然后我可以在需要的时候给这个数据一个onclick handlers。这个固然可以,不过难以维护且有点凌乱。

  现在如果我使用CSS类来实现,face up的纸牌我通过addclass方法为它们加上一个'flipped'类,然后可以通过一个简单的 '$(".card:not(.flipped)")'选择那些face down的纸牌。使用jQuery的click(fn)功能能够让我使用几行代码就实现这个功能。更重要的是它更容易理解和读取。

下面附上几点英文原版的:

3。Understand unobtrusive Javascript. 
 In the ASP.NET world, we use a lot of what's sometimes termed obtrusive Javascript.  This means that client-side event handlers are defined as attributes on elements.  For example, several ASP.NET WebControls render an OnClick=”Javascript:__doPostBack()”attribute as part of their markup.  This is considered obtrusive Javascript.

When ASP.NET was initially being developed, this inline Javascript was the norm.  However, as browsers began providing more sophisticated faculties for imperatively adding event handlers, this declarative technique quickly lost favor with client-side developers. As a consequence, the preferred approach has shifted toward what's called unobtrusive Javascript.

Unobtrusive Javascript is now considered a best practice when wiring up client-side event handlers.  This is primarily because it facilitates separation of concerns between behavioral Javascript and structural HTML markup.  Unobtrusive Javascript also helps you to write cleaner, more semantic markup, which improves accessibility and often has SEO benefits.

  • Use the console to learn interactively.
    Coming from the save-compile-reload paradigm of statically typed server-side development, it's natural to approach client-side development in a similar fashion.  While you certainly can write client-side code that way, it's akin to working blindfolded when you consider the alternatives.

    Since Javascript is usually interpreted by a browser, the browser is one of the best debugging environments available.  In particular, a Javascript “console” is terrific for interactively interrogating the DOM, testing jQuery selectors against actual markup, and refining Javascript code in real-time.

    My preferred browser-based tool is the
    Firebug addon to Firefox.  I cannot praise this Firebug highly enough.  It has revolutionized how I approach client-side development, both of Javascript and of CSS.  If you prefer Internet Explorer, IE8's updated developer tools are also very capable in this department.
    Whatever your browser of choice, I urge you to give these utilities a try when debugging client-side functionality.  Once you become proficient with one of these tools, you'll be amazed that you ever developed client-side code without it.
  • Get the VSDOC.
    Even though browser-based tools are great for debugging, an ASP.NET developer's primary editor is still going to be Visual Studio.  When writing jQuery code in Visual Studio, having proper Intellisense can make a tremendous difference in productivity.  The discoverability that Intellisense provides is especially beneficial when you're unfamiliar with jQuery's API.

    As part of the official support for jQuery, Microsoft provides a documentation file to provide jQuery Intellisense inside Visual Studio 2008.  This is provided through what's called a vsdoc file, and is available on the
    jQuery download page (via the “Documentation: Visual Studio” links).
    Jeff King has assembled an excellent FAQ to help you get Visual Studio 2008's Javascript Intellisense working: 
    http://blogs.msdn.com/webdevtools/archive/2008/11/18/jscript-intellisense-faq.aspx

  • 推荐阅读
    • CSS3选择器的使用方法详解,提高Web开发效率和精准度
      本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
    • 知识图谱——机器大脑中的知识库
      本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
    • Voicewo在线语音识别转换jQuery插件的特点和示例
      本文介绍了一款名为Voicewo的在线语音识别转换jQuery插件,该插件具有快速、架构、风格、扩展和兼容等特点,适合在互联网应用中使用。同时还提供了一个快速示例供开发人员参考。 ... [详细]
    • 本文介绍了在Ubuntu下制作deb安装包及离线安装包的方法,通过备份/var/cache/apt/archives文件夹中的安装包,并建立包列表及依赖信息文件,添加本地源,更新源列表,可以在没有网络的情况下更新系统。同时提供了命令示例和资源下载链接。 ... [详细]
    • 本文介绍了使用jQuery实现图片预加载和等比例缩放的方法,同时提供了演示和相关代码。该方法可以重置图片的宽度和高度,并使图片在水平和垂直方向上居中显示。 ... [详细]
    • 如何压缩网站页面以减少页面加载时间
      本文介绍了影响网站打开时间的两个因素,即网页加载速度和网站页面大小。重点讲解了如何通过压缩网站页面来减少页面加载时间。具体包括图片压缩、Javascript压缩、CSS压缩和HTML压缩等方法,并推荐了相应的压缩工具。此外,还提到了一款Google Chrome插件——网页加载速度分析工具Speed Tracer。 ... [详细]
    • angular.element使用方法及总结
      2019独角兽企业重金招聘Python工程师标准在线查询:http:each.sinaapp.comangularapielement.html使用方法 ... [详细]
    • 前言:关于跨域CORS1.没有跨域时,ajax默认是带cookie的2.跨域时,两种解决方案:1)服务器端在filter中配置详情:http:blog.csdn.netwzl002 ... [详细]
    • jQuery :nthchild前有无空格的区别
      :nth-child(index)子元素过滤选择器的描述是:选取每个父元素下的弟index个子元素,index从1开始。然后,我写了如下h ... [详细]
    • 本文介绍了使用Java实现大数乘法的分治算法,包括输入数据的处理、普通大数乘法的结果和Karatsuba大数乘法的结果。通过改变long类型可以适应不同范围的大数乘法计算。 ... [详细]
    • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
    • 本文介绍了DataTables插件的官方网站以及其基本特点和使用方法,包括分页处理、数据过滤、数据排序、数据类型检测、列宽度自动适应、CSS定制样式、隐藏列等功能。同时还介绍了其易用性、可扩展性和灵活性,以及国际化和动态创建表格的功能。此外,还提供了参数初始化和延迟加载的示例代码。 ... [详细]
    • 获取ul中第一个li元素的五种方法和多个ul中第一个li元素的四种方法
      本文介绍了获取ul中第一个li元素的五种方法和多个ul中第一个li元素的四种方法,包括使用jQuery的选择器和遍历方法。通过这些方法,可以方便地获取到所需的元素,并进行相应的操作。 ... [详细]
    • mui框架offcanvas侧滑超出部分隐藏无法滚动如何解决
      web前端|js教程off-canvas,部分,超出web前端-js教程mui框架中off-canvas侧滑的一个缺点就是无法出现滚动条,因为它主要用途是设置类似于qq界面的那种格 ... [详细]
    • 025_JavaScript数组方法
      1.把数组转换为字符串1.1.toString()方法1.1.1.toString()方法把数组转换为数组值(逗号分隔)的字符串,并返回结果。1.1.2.语法arrayOb ... [详细]
    author-avatar
    Me丶i丶晓莹丬_690
    这个家伙很懒,什么也没留下!
    PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
    Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有