Browser Independence issue Code Working for IE but not for Firefox and Chrome

前端 未结 2 996
一整个雨季
一整个雨季 2021-01-17 02:41

if i run the same code for IE every thing is fine i am getting the value of selectedId where as for firefox and chrome it is giving values Undefine.

-------         


        
相关标签:
2条回答
  • 2021-01-17 03:37

    In Chrome (sorry, I'm using a computer that doesn't have FF, and I'm not going to install it just for this question) it works if you use .getAttribute(). So:

    // replace
    e.selectedId;
    // with
    e.getAttribute("selectedId");
    

    Or, in your function:

    var id = e.getAttribute("selectedId");
    console.log("the value of selected IDS="+id );
    if (id != null)
    {   
        value += ", "+id;
    }
    

    Also, note that JavaScript is case sensitive, so your variable value is not the same as Value, and you were saying Value = where you probably meant value +=. And you may want to use quotes around your element attributes: onclick="createSelected()".

    0 讨论(0)
  • 2021-01-17 03:41

    Try reading the selectedId as below. Use getAttribute method

    alert("the value of selected IDS="+e.getAttribute('selectedId'));

    0 讨论(0)
提交回复
热议问题