InnerHTML and Getelementsbyname solutions for bugs under IE _javascript tips

Source: Internet
Author: User
For example, there is such a problem.
Copy Code code as follows:

<div id= "Playlist" >
</div>

In this Div, add a play list. This list is added with innerHTML.
Copy Code code 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=" Playi NG_BG "Name=" PLAYING_BG "></div>";
TXT + + <div class= "playing" Name= "playing" > is 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;
}
}

The complex code in the middle doesn't have to be taken care of, now I'm going to take the name playing div out. It's easy to think of using
Getelementsbyname
However, it's very strange that you can't get it under IE. getElementById can be used completely.
Here's a good solution:
Copy Code code 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;
}

Change to this function, you can take it. It just takes one more argument.
Do not know Bo friends have other solutions, this solution is not very perfect. Be sure to leave a message in the comments.

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.