javascript在IE和Firefox中的区别1

1.调用appendChild方法增加input对象,设置type属性的位置
   
 1 None.gif    < html >
 2 None.gif     < head >
 3 None.gif     < title > test </ title >
 4 ExpandedBlockStart.gifContractedBlock.gif     < script  language ="javascript" > dot.gif
 5ExpandedSubBlockStart.gifContractedSubBlock.gif    function test()dot.gif{
 6InBlock.gif        var tbodyElement=document.getElementById("tbody1");
 7InBlock.gif        var trElement=document.createElement("tr");
 8InBlock.gif        var idTDElement=document.createElement("td");
 9InBlock.gif        
10InBlock.gif        idTDElement.innerHTML=1;
11InBlock.gif        var nameTDElement=document.createElement("td");
12InBlock.gif        
13InBlock.gif        var inputElement=document.createElement("input");
14InBlock.gif        nameTDElement.appendChild(inputElement);
15InBlock.gif        inputElement.type="button";  
16InBlock.gif        //在IE中,这句话将会抛出异常,但在firefox能正常运行,如果type为text或者不设置type属性,也都能正常运行
17InBlock.gif        inputElement.value="Invoke";
18ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//*
19InBlock.gif        修改成下面的语句就能正常运行:
20InBlock.gif        var inputElement=document.createElement("input");
21InBlock.gif        inputElement.type="button";
22InBlock.gif        nameTDElement.appendChild(inputElement);
23ExpandedSubBlockEnd.gif        */

24InBlock.gif        
25InBlock.gif        tbodyElement.appendChild(trElement);
26InBlock.gif        trElement.appendChild(idTDElement);
27InBlock.gif        trElement.appendChild(nameTDElement);
28ExpandedSubBlockEnd.gif    }

29ExpandedBlockEnd.gif    
</ script >
30 None.gif     </ head >
31 None.gif     < body >
32 None.gif         < input  type ="button"  value ="insert"  onclick ='test()' >
33 None.gif         < table  cellpadding ="0"  cellspacing ="0"  border ="1" >
34 None.gif             < tbody  id ='tbody1' >
35 None.gif                 < tr >
36 None.gif                     < td  width ="50" > ID </ td >
37 None.gif                     < td  width ="200" > name </ td >
38 None.gif                 </ tr >
39 None.gif             </ tbody >
40 None.gif         </ table >
41 None.gif     </ body >
42 None.gif   </ html >  
 
2.appendChild一个radio对象,设置该对象的name属性
 1 None.gif    var  nameTDElement = document.createElement( " td " );  
 2 None.gif   var  radioElement = document.createElement( " input " );
 3 None.gif  radioElement.type = " radio " ;
 4 None.gif  nameTDElement.appendChild(inputElement);
 5 None.gif  radioElement.name = " testRadioName " ;   // 这句话在firefox是起作用的,但在IE下是不起作用的
 6 ExpandedBlockStart.gifContractedBlock.gif    /**/ /*解决的办法是
 7InBlock.gif  var radioElement=document.createElement("<input name='testRadioName'>");
 8InBlock.gif  radioElement.type="radio";
 9InBlock.gif  nameTDElement.appendChild(inputElement);
10ExpandedBlockEnd.gif  */

3.对select控件增加和删除Option
 1 None.gif    < html >
 2 None.gif     < head >
 3 None.gif     < title > test </ title >
 4 ExpandedBlockStart.gifContractedBlock.gif     < script  language ="javascript" > dot.gif
 5ExpandedSubBlockStart.gifContractedSubBlock.gif    function deleteRow()dot.gif{
 6InBlock.gif        var selectElement=document.getElementById("select1");
 7InBlock.gif        selectElement.options.remove(1);  //IE:OK        Firefox:Failure
 8InBlock.gif        selectElement.remove(1);          //IE:OK        Firefox:OK
 9ExpandedSubBlockEnd.gif    }

10ExpandedSubBlockStart.gifContractedSubBlock.gif    function insertRow()dot.gif{
11InBlock.gif        var selectElement=document.getElementById("select1");
12InBlock.gif        var option=new Option("eeee",5);        
13InBlock.gif        selectElement.add(option);        //IE:OK        Firefox:Failure
14InBlock.gif        selectElement.options.add(option);//IE:OK        Firefox:OK
15ExpandedSubBlockEnd.gif    }

16ExpandedBlockEnd.gif    
</ script >
17 None.gif     </ head >
18 None.gif     < body >
19 None.gif     < input  type ="button"  value ="Delete"  onclick ='deleteRow()' >
20 None.gif     < input  type ="button"  value ="Insert"  onclick ='insertRow()' >
21 None.gif     < select  id ="select1" >
22 None.gif         < option   value ="1" > aaa </ option >
23 None.gif         < option   value ="2" > bbb </ option >
24 None.gif         < option   value ="3" > ccc </ option >
25 None.gif         < option   value ="4" > ddd </ option >
26 None.gif     </ select >
27 None.gif     </ body >
28 None.gif   </ html >     

   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值