1.3 jquery Basics

Source: Internet
Author: User

jquery files need to be referenced with jquery (jquery at the top of the page referencing multiple JS files)

<script src="jquery-1.11.2.min.js"></script>

The "$" symbol represents the selector

<script type="text/javascript">

     $(document).ready( function (e) {     function是匿名函数,e是形参          }); </script> JS中的找元素,DOM对象 var a = document.getElementById("");  根据id找 alert(); var a = document.getElementsByClassName("");  根据class名找 alert(); var a = document.getElementsByTagName("");   根据标签找 var a = document.getElementsByName("");   根据name找Jquery:var A = $ ("#aa"); Search by ID (#) var a = $( ".bb" );   根据class名找(.) var a = $( "div" );   根据标签名找(标签名称) var a = $( "[name=‘cc‘]" );   根据属性找(属性名称)jquery Operation Properties: a.attr("","");(设置)   alert(a.attr(""));(获取) a.removeAttr("");(移除)jquery event: Single Add: <input type= "button" value= "测试" id=  "btn" /> $( "#btn" ).click( function (){ 
    alert( "czx" );   });    会显示czxMultiple additions: <input type= "button" value= "测试1" class "btn" /> <input type= "button" value= "测试2" class "btn" /> <input type= "button" value= "测试3" class "btn" /> $( ".btn" ).click( function (){      //alert("czx111");        alert($(this).val());        });      通过class名找到要修改的元素,谁触发的它,this就代表谁Hang Event: <input type= "button" value= "挂事件" id=  "gua" /> <input type= "button" value= "测试事件" id=  "ceshi" /> <input type= "button" value= "移除事件" id=  "yichu" />

Click the test Events button to hang an event
$ ("#gua"). Click (function () {(bind bind method for hanging Events)
$ ("#ceshi"). bind ("click", function () {
Alert ("hang up the event");
});
});

Click the Test Event button to remove the Click event
$ ("#yichu"). Click (function () {(unbind Method (the event name to UNBIND))
$ ("#ceshi"). Unbind ("click");
})

});

1.3 jquery Basics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.