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 ~