How to solve the bug of innerHTML and getElementsByName in IE

Source: Internet
Author: User

For example, there is such a problem.
Copy codeThe Code is as follows:
<Div id = "playlist">
</Div>

Add a playlist to this div. This list is added with innerHTML.
Copy codeThe Code is as follows:
Var plst = null;
Plst = player. getPlaylist ();
If (plst ){
Var txt = '';
For (var I in plst ){
Txt + = '<a name = "fv_item_a _' + I + '"> </a> <div class = "fv_item" id = "fv_item _' + I + '"> <div class = "playing_bg" name = "playing_bg"> </div> ';
Txt + = '<div class = "playing" name = "playing"> playing... </div> ';
Txt + = ' ';
Txt + = '<p class = "fv_playlist_title">' + plst [I]. title + '</p> ';
Txt + = "</div> ";
}
Var obj = document. getElementById ("playlist ");
If (obj ){
Obj. innerHTML = txt;
}
}

You don't have to worry about complicated code in the middle. Now I want to retrieve the div whose name is playing. Easy to use
GetElementsByName
However, it is very strange that it cannot be obtained under ie. GetElementById is fully usable.
Below is a good solution:
Copy codeThe Code is as follows:
Function GetElementsByName (tag, name ){
Var elem = document. getElementsByTagName (tag );
Var arr = [];
Var index = 0;
Var l = elem. length;
For (var I = 0; I <l; I ++)
{
Var att = elem [I]. getAttribute ("name ");
If (att = name ){
Arr [index ++] = elem [I];
}
}
Return arr;
}

You can use this function. Only one more parameter is required.
I don't know if there are any other solutions for bloggers. This solution is not perfect. Leave a message in the comment.

Related Article

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.