JQuery $.fn Method Extension ~

Source: Internet
Author: User

The following code immediately follows the introduction of the Jquery.js code

<script type= "Text/javascript" >

$ (function () {

Extended MyName Method This method is similar to the default check string from start to end: # This is the topic # Effect

$.fn.myname (function (start, end) {

var txtstr= $ (this). Get (0);

if (txtstr==null) {return;}

else if (txtstr. Setselectionrange) {

Txtstr.focus ();

Txtstr.createtextrange (start, end);

}

else if (txtstr. createTextRange) {

var txt = txtstr.createtextrange ();

Txt.collapse (TRUE);

Txt.moveend (' character ', end);

Txt.movestart (' character ', start);

Txt.select ();

}

else if (txtstr. SelectionStart) {

Txtstr.selectionstart=start;

Txtstr.selectionend=end;

}

})

})

</script>

———— the above code for the jquery extension ————

———— the following to use the extension method ————

$ (#id). Click (function () {

This means assigning a text box with ID ID "#请输入话题 #" and selecting "Please enter a topic" That is: # Please enter a topic #效果

$ (#id). Val (' #请输入话题 # ') myName (1,6);//starting from 1 to sixth (excluding 6th)

})

JQuery $.fn Method Extension ~

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.