Jquery code example of Douban.com

Source: Internet
Author: User

Method To be executed after the document is loaded (see the jquery document)
Generally, all events should be bound during document loading, but there is one exception.
For example, if the content retrieved through the Ajax method also contains action buttons, you need to bind these functions. CopyCode The Code is as follows: // you need to manually call load_event_monitor (element); method.
$ (Function (){
Load_event_monitor (document );
});
// Note that the O object here is an HTML element rather than a jquery object, so you should use the $ (o) function when calling its method.
// Convert it to a jquery object.
Bowtech. init_forder = function (o ){
VaR eid = $ (O). ATTR ("ID"). Split ("-") [1];
VaR fo = $ ("# F-" + EID );
VaR unfo = $ ("# UNF-" + EID );

Fo. Click (function (){
$ (O). Hide ();
Unfo. Show ();
Fo. Hide ();
});
Unfo. Click (function (){
$ (O). Show ();
Fo. Show ();
Unfo. Hide ();
});
}

Jquery. FN. Extend ({
Set_caret: function (){
If (! $. Browser. MSIE) return;
VaR initsetcaret = function () {This. caretpos = Document. selection. createRange (). Duplicate ()};
This. Click (initsetcaret). Select (initsetcaret). keyup (initsetcaret );
},
Insert_caret: function (textfeildvalue ){
VaR textobj = This [0];
If (document. All & textobj. createTextRange & textobj. caretpos ){
VaR caretpos = textobj. caretpos;
Caretpos. Text = caretpos. Text. charat (caretpos. Text. Length-1) = "? Textfeildvalue + ": textfeildvalue;
} Else if (textobj. setselectionrange ){
VaR rangestart = textobj. selectionstart;
VaR rangeend = textobj. selectionend;
VaR tempstr1 = textobj. value. substring (0, rangestart );
VaR tempstr2 = textobj. value. substring (rangeend );
Textobj. value = tempstr1 + textfeildvalue + tempstr2;
Textobj. Focus ();
VaR Len = textfeildvalue. length;
Textobj. setselectionrange (rangestart + Len, rangestart + Len );
Textobj. Blur ();
} Else {
Textobj. Value + = textfeildvalue;
}
}
})

The front-end is easy to use. You only need to write it like this:

Copy code The Code is as follows: <Div id = "Test2" class = "Mod">
<H3>
The title can be set here.
</H3>
<Div class = "J modb a_forder" id = "modb-1002">
Here are some main contents
<DL>
<DT> Hello World </DT>
<DD>
Hahaha </DD>
</Dl>
This experiment was completed in shenzhouben of shujia.
</Div>
<Div class = "edit">
<A id = "f-1002" class = "forder" href = "javascript: void (0);"> [collapse] </a> <a id = "unf-1002 ″
Class = "unforder" href = "javascript: void (0);"> [Expand] </a>
</Div>
</Div>

The style is omitted. You can write it by yourself and then send two messages:

Collapsed

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.