An insertadjacenthtml method compatible with FF in ext2

Source: Internet
Author: User

Recently, I am working on a multi-File Upload component, which has been implemented in IE and can be used to dynamically add uploaded attachments. however, in the next test of FF, no response was found. I used insertadjacenthtml. no way. note that there is an insertadjacenthtml method compatible with FF in ext2. copy the file.

 

<SCRIPT type = "text/JavaScript">
<! --
Function inserthtml (where, El, HTML ){
Where = where. tolowercase ();
If (El. insertadjacenthtml ){
Switch (where ){
Case "beforebegin ":
El. insertadjacenthtml ('beforebegin', HTML );
Return El. previussibling;
Case "afterbegin ":
El. insertadjacenthtml ('afterin in', HTML );
Return El. firstchild;
Case "beforeend ":
El. insertadjacenthtml ('foreend', HTML );
Return El. lastchild;
Case "afterend ":
El. insertadjacenthtml ('afterend', HTML );
Return El. nextsibling;
}
Throw 'illegal insertion point-> "'+ where + '"';
}
VaR range = El. ownerdocument. createRange ();
VaR frag;
Switch (where ){
Case "beforebegin ":
Range. setstartbefore (EL );
Frag = range. createcontextualfragment (HTML );
El. parentnode. insertbefore (frag, El );
Return El. previussibling;
Case "afterbegin ":
If (El. firstchild ){
Range. setstartbefore (El. firstchild );
Frag = range. createcontextualfragment (HTML );
El. insertbefore (frag, El. firstchild );
Return El. firstchild;
} Else {
El. innerhtml = HTML;
Return El. firstchild;
}
Case "beforeend ":
If (El. lastchild ){
Range. setstartafter (El. lastchild );
Frag = range. createcontextualfragment (HTML );
El. appendchild (frag );
Return El. lastchild;
} Else {
El. innerhtml = HTML;
Return El. lastchild;
}
Case "afterend ":
Range. setstartafter (EL );
Frag = range. createcontextualfragment (HTML );
El. parentnode. insertbefore (frag, El. nextsibling );
Return El. nextsibling;
}
Throw 'illegal insertion point-> "'+ where + '"';
}

Parameter introduction:
Where: insert position. Includes beforebegin, beforeend, afterbegin, and afterend.
El: Used to reference the HTML element object at the inserted position
HTML: the HTML code to insert

 

Everything is OK.

I 've been looking at ext Resources recently and have gained a lot. If you are interested, please take a look.

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.