国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET開發(fā)者使用jQuery應(yīng)該了解的幾件事情

2024-07-10 13:19:26
字體:
供稿:網(wǎng)友

下面這幾點(diǎn)希望能夠幫你加快你的學(xué)習(xí)。

1.把selectors當(dāng)作asp.net中的sets。

   在asp.net的世界,通過一個(gè)查詢找到一系列控件是非常少見的.相反我們比較習(xí)慣于通過一個(gè)唯一的ID來找到一個(gè)控件。當(dāng)然,在jQuery中這個(gè)也是沒有問題的,但是jQuery的選擇功能相對更加神奇。

   使用jQuery的selectors能夠很容易定位到一個(gè)set的元素,相對來說比在asp.net中使用迭代的規(guī)則來找到一個(gè)set的元素更加清晰和易于表達(dá)。

2.使用CSS類來代替styling。

   另外一個(gè)不直觀的技術(shù)是把CSS類作為一個(gè)flag。與'selector engin'一樣,'flag'類也是個(gè)令人驚喜的東西。

   舉個(gè)例子來說吧,最近有個(gè)活動(dòng)是做一個(gè)在線的能夠與客戶端互動(dòng)的紙牌游戲。一個(gè)需求是紙牌需要有個(gè)onclick haddler在某個(gè)特定時(shí)間,不過這些事件只針對那些face down(臉朝下)的。作為一個(gè).net的開發(fā)者我立刻能夠想到的辦法是讓這些紙牌在客戶端通過一個(gè)collection來編號(hào).然后我可以在需要的時(shí)候給這個(gè)數(shù)據(jù)一個(gè)onclick handlers。這個(gè)固然可以,不過難以維護(hù)且有點(diǎn)凌亂。

  現(xiàn)在如果我使用CSS類來實(shí)現(xiàn),face up的紙牌我通過addclass方法為它們加上一個(gè)'flipped'類,然后可以通過一個(gè)簡單的 '$(".card:not(.flipped)")'選擇那些face down的紙牌。使用jQuery的click(fn)功能能夠讓我使用幾行代碼就實(shí)現(xiàn)這個(gè)功能。更重要的是它更容易理解和讀取。

下面附上幾點(diǎn)英文原版的:

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.

  • 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.
  • 發(fā)表評論 共有條評論
    用戶名: 密碼:
    驗(yàn)證碼: 匿名發(fā)表
    主站蜘蛛池模板: 吉木萨尔县| 上杭县| 鞍山市| 广南县| 保德县| 大方县| 韶山市| 吉安县| 衢州市| 大余县| 株洲市| 玉溪市| 湟源县| 措美县| 神木县| 新营市| 固阳县| 桃园县| 岚皋县| 长垣县| 宁安市| 阜平县| 富川| 水城县| 清原| 龙州县| 江川县| 米林县| 木里| 隆尧县| 华安县| 志丹县| 东丽区| 岑溪市| 独山县| 樟树市| 延川县| 台北县| 峨边| 广平县| 台南县|