日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

jquery in action 学习笔记

發布時間:2023/12/13 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 jquery in action 学习笔记 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1

面對對象的編程

1.引用傳遞

在javascript中,string int Boolean 不是按引用進行傳遞的.而對象和數組是按引用傳遞的.

示例:

?//?Create?an?array?of?items
var?items?=?new?Array("one",?"two",?"three");
//?Create?a?reference?to?the?array?of?items
var?itemsRef?=?items;
//?Add?an?item?to?the?original?array
items.push("four");
//?The?length?of?each?array?should?be?the?same,
//?since?they?both?point?to?the?same?array?object
alert(items.length?==?itemsRef.length); 結果是 true

2.每一個Function中都有一個上下文變量arguments,它是一個偽數組(不可以改變).它代表著當前Function的參數列表.

?在javascript中,變量的作用域是整個Function,而不是{}.這點有別于c#等其他語言.


//?Set?a?global?variable,?foo,?equal?to?test
var?foo?=?"test";
//?Within?an?if?block
if?(true)?{
//?Set?foo?equal?to?'new?test'
//?NOTE:?This?is?still?within?the?global?scope!
var?foo?=?"new?test";
}
//?As?we?can?see?here,?as?foo?is?now?equal?to?'new?test'
alert(foo?==?"new?test");
//?Create?a?function?that?will?modify?the?variable?foo
function?test()?{
var?foo?=?"old?test";
}
//?However,?when?called,?'foo'?remains?within?the?scope
//?of?the?function
test();
//?Which?is?confirmed,?as?foo?is?still?equal?to?'new?test'
alert(foo?==?"new?test");

// A globally-scoped variable, containing the string 'test'

var test = "test";

// You'll notice that our 'global' variable and the test

// property of the the window object are identical

alert( window.test == test );

全局變量可以理解為window的屬性.

編寫javascript代碼時的一些注意事項:

  • 要對使用的變量進行聲明.以避免不同的作用域時的沖突.
  • 理解0 false ‘’ undefined null 這些值在javascript里是相同的,都等于false.
  • // Both of these are true

    null == false

    0 == undefined

    // You should use !== or === instead

    null !== false

    false === false

    DOM 編程

    <p><strong>Hello</strong> how are you doing?</p>

    使用DOM的時候,小心一些空白(text)造成的影響,經常使你能找到自己想要的目標元素. function cleanWhitespace( element ) {

    // If no element is provided, do the whole HTML document

    element = element || document;

    // Use the first child as a starting point

    var cur = element.firstChild;

    // Go until there are no more child nodes

    while ( cur != null ) {

    // If the node is a text node, and it contains nothing but whitespace

    if ( cur.nodeType == 3 && ! /\S/.test(cur.nodeValue) ) {

    // Remove the text node

    element.removeChild( cur );

    // Otherwise, if it's an element

    } else if ( cur.nodeType == 1 ) {

    // Recurse down through the document

    cleanWhitespace( cur );

    }

    cur = cur.nextSibling; // Move through the child nodes

    }

    }

    ?使用nodeType屬性.

    Element (nodeType = 1):如li a input select等元素.

    Text (nodeType = 3): 匹配文本元素

    Document (nodeType = 9): This matches the root element of a document.

    獲取元素內的文本內容

    需要注意的是innertext在非mozilla瀏覽器中可以使用,火狐中無法使用.

    Listing 5-15. Getting the Text Contents of the <strong> Element

    // Non-Mozilla Browsers:

    strongElem.innerText

    // All platforms:

    strongElem.firstChild.nodeValue

    獲取元素內的html

    ? Mozilla-based browsers don’t return the <style> elements in an innerHTML statement.

    ? Internet Explorer returns its elements in all caps, which if you’re looking for consistency

    can be frustrating.

    ? The innerHTML property is only consistently available as a property on elements of HTML DOM documents; trying to use it on XML DOM documents will result in retrieving null values.

    獲取或設置一個元素的屬性值 getAttribute SetAttribute.

    Jquery代碼學習

    Jquery in action 選擇器部分學習

    Ul li a 不管多少層次,會選中所有符合ul li 下的a.不管多少層級.

    Ul li>a 只選擇直接孩子的a標簽.

    Li:has(a)容器選擇器,選擇包含鏈接的li元素以進行某項操作.

    通過位置進行定位的選擇器.

    ??

    Jquery自定義的篩選選擇器:

    ?//防止重復提交的一個方法 w3c官方推薦的屬性設置 ????????????$("form").submit(function?()?{
    $(":submit").attr("disabled",?"disabled");
    }); ?

    轉載于:https://www.cnblogs.com/huaxiaoyao/archive/2011/02/16/1956526.html

    總結

    以上是生活随笔為你收集整理的jquery in action 学习笔记的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。