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

前端 未结 2 1015
一整个雨季
一整个雨季 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()".

提交回复
热议问题