浏览器独立问题代码适用于IE

浏览器独立问题代码适用于IE

本文介绍了浏览器独立问题代码适用于IE,但不适用于Firefox和Chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我运行相同的代码为IE浏览器的每一件事情都很好,我得到的selectedId的价值,其中为Firefox和铬是给值Undefine。

  ----------------- code -------- ----------------------- 

< html>
< head>
< script type =text / javascript>

函数createSelected()
{
var value;
var theForm = document.hell;

for(var i = 0; i< theForm.length; i ++)
{
var e = theForm.elements [i];
if((e.type ==hidden)&(e.value ==false))
{
console.log(所选IDS的值=+ e.selectedId);
if(e.selectedId!= undefined)
{
Value =,+ e.selectedId;



$ b console.log(Value);
}


< / script>
< / head>
< body>
< form name =hell>

< h1>这个只适用于IE不能与FireFox和Crome< / h1>
< br />
< br />
< input type =hiddenselectedId =heyya1name =item1value =false> h1< / input>
< input type =hiddenselectedId =heyya2name =item2value =false> h2< / input>
< input type =hiddenselectedId =heyya3name =item3value =false> h3< / input>
< input type =hiddenselectedId =heyya4name =item4value =false> h4< / input>
< input type =hiddenselectedId =heyya5name =item5value =false> h5< / input>
< input type =hiddenselectedId =heyya6name =item6value =false> h6< / input>
< input type =buttononclick = createSelected()value =find the values>< / input>
< / form>


< / body>

--------------------------- code end ------------- ----------------------------

请帮忙,为什么我们不能使用FireFox中的其他参数(比如HTML中的Selectedid),就像我们在IE中可以这样做。



在预先感谢。

解决方案

在铬(对不起,我使用的电脑没有FF,我不打算安装它只是为了这个问题),如果你使用。所以:

  //替换
e.selectedId;
//带
e.getAttribute(selectedId);

或者,在您的函数中:

  var id = e.getAttribute(selectedId); 
console.log(所选IDS的值=+ id);
if(id!= null)
{
value + =,+ id;另外,请注意JavaScript是区分大小写的,所以你的变量<$ c




$ b $ p $ c> value
Value 不一样,并且您在说 Value = where你可能意思是 value + = 。你可能想要在元素属性周围使用引号: onclick =createSelected()


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.

----------------- code -------------------------------

<html>
<head>
<script type="text/javascript">

function createSelected()
{
var value;
var theForm = document.hell;

for (var i = 0; i < theForm.length; i++)
{
var e = theForm.elements[i];
if ((e.type == "hidden") && (e.value == "false"))
{
       console.log("the value of selected IDS="+e.selectedId);
    if (e.selectedId!= undefined )
    {
        Value = ", "+e.selectedId;

    }
}
}
console.log( Value);
}


</script>
</head>
<body>
<form name="hell">

<h1>This working only with IE not with FireFox and Crome  </h1>
<br/>
<br/>
<input type="hidden" selectedId="heyya1"  name="item1" value="false">h1</input>
<input type="hidden" selectedId="heyya2"  name="item2" value="false">h2</input>
<input type="hidden" selectedId="heyya3"  name="item3" value="false">h3</input>
<input type="hidden" selectedId="heyya4"  name="item4" value="false">h4</input>
<input type="hidden" selectedId="heyya5"  name="item5" value="false">h5</input>
<input type="hidden" selectedId="heyya6"  name="item6" value="false">h6</input>
<input type="button" onclick=createSelected() value="find the values"></input>
</form>


</body>

---------------------------code end-----------------------------------------

please help in in this why cant we use other parameter( like Selectedid inside HTML tag) in FireFox like we can do it in IE.

thanks in advance..

解决方案

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()".

这篇关于浏览器独立问题代码适用于IE,但不适用于Firefox和Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 06:42