getElementsByClassName IE解析问题 [英] getElementsByClassName IE resolution issue

查看:94
本文介绍了getElementsByClassName IE解析问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在解决如何解决IE中的getElementsByClassName问题时遇到了问题。我如何最好地实现罗伯特·尼曼(不能发布链接,因为我的代表只有1)解析到我的代码?或者jquery解决方案会更好吗?我的代码是

I am having issues figuring out how to resolve the getElementsByClassName issue in IE. How would I best implement the robert nyman (can't post the link to it since my rep is only 1) resolution into my code? Or would a jquery resolution be better? my code is

function showDesc(name) {
var e = document.getElementById(name);
//Get a list of elements that have a class name of service selected
var list = document.getElementsByClassName("description show");

//Loop through those items
for (var i = 0; i < list.length; ++i) { 
    //Reset all class names to description
    list[i].className = "description";
}

if (e.className == "description"){
    //Set the css class for the clicked element
    e.className += " show";
}
else{
    if (e.className == "description show"){
        return;
    }
}}

我正在此页面上使用 dev.msmnet.com/services/practice-management 显示/隐藏每项服务的说明(适用于Chrome和FF)。任何提示都将非常感激。

and I am using it on this page dev.msmnet.com/services/practice-management to show/hide the description for each service (works in Chrome and FF). Any tips would be greatly appreciated.

推荐答案

我很想知道你的函数的jQuery版本会是什么样子,所以我得出这个:

I was curious to see what a jQuery version of your function would look like, so I came up with this:

function showDesc(name) {
    var e = $("#" + name);
    $(".description.show").removeClass("show");
    if(e.attr("class") == "description") {
        e.addClass("show");
    } else if(e.hasClass("description") && e.hasClass("show")) {
        return;
    }
}

这篇关于getElementsByClassName IE解析问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆