首页 > javascript > javascript兼容firefox,谷歌,IE取值的方法

javascript兼容firefox,谷歌,IE取值的方法

2009年12月23日 云飞扬 发表评论 阅读评论

firefox,谷歌 中只支持document.getElementById("id")
IE支持document.getElementById("id") 和name
测试例子如下:IE中时把c,d取消注释, firefox,谷歌增加注释,本想用onload,但是firefox,谷歌也不支持

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="testweb._Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
    <script>
        function init() {
            var a = document.getElementById("id1").value;
            var b = document.getElementById("id2").value;
//            var c = document.getElementById("id3").value;
//            var d = document.getElementById("id4").value;
 
            alert(a);
            alert(b);
//            alert(c);
//            alert(d);
        }
 
    </script>
 
</head>
<body >
    <form id="form1" runat="server">
    <div>
    <input id="id1" type="text" value="测试1"   />
    <input id="id2" type="text" value="测试2"   />
      <input type="text" value="测试3" name="id3" />
    <input  type="text" value="测试4" name="id4" />
    <input type="button" onclick="init()" value="测试" />
    </div>
    </form>
</body>
</html>

原创文章转载请注明出处:云飞扬IT的blog

本文链接: http://www.ajaxcn.net/archives/671

  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.