用户操作
[即时聊天] [发私信] [加为好友]
aaronbaiID:aaronbai
61074次访问,排名1732好友5人,关注者9
aaronbai的文章
原创 76 篇
翻译 0 篇
转载 18 篇
评论 18 篇
最近评论
gaoweijin:我 ok了
zhangkai08111:不ok啊。。
zhangkai08111:不ok啊。。
itzoey:懂了
感谢
longhua3311:我是在my.ini文件里改的
文章分类
收藏
    相册
    好友BLOG
    Aaronbai的猫窝
    学习交流
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 实现ajax时一些跨浏览器的js方法收藏

    新一篇: vs2008新特性 | 旧一篇: 在ASP.NET中实现自定义分页功能

    以下是实现ajax时一些跨浏览器的js方法,这些方法在任何浏览器中都可达到同样的效果。


    一. 向表中追加行

    定义table时使用tbody元素,以保证包括IE在内的所有浏览器可用

    例:定义如下一个空表

    <table id=”myTable”>

          <tbody id=”myTableBody”></tbody>

    </table>

    向这个表中增加行的正确做法是,把行增加到表体,而不是增加到表。

    Var cell = document.createElement(“td”).appendChild(document.createTextNode(“foo”));

    Var row = document.createElement(“tr”).appendChild(cell);

    Document.getElementById(“myTableBody”).appendChild(row);

    *IE中需要先创建行,再创建列,再创建内容

    二:  设置元素的样式

    Var spanElement = document.getElementById(“mySpan”);

    //下面写法保证出IE外,所有浏览器可用

    spanElement.setAttribute(“style”,”font-weight:bold;color:red;”);

    //下面的写法保证IE可用

    spanElement.style.cssText=”font-weight:bold;color:red;”;

    所以使用时把以上两句都写上。

    三、设置元素的class属性

    Var element = document.getElementById(“myElement”);

    //下面的写法保证除IE外,所有浏览器可用

    Element.setAttribute(“class”,”styleClass”);

    //下面写法保证IE可用

    Element.setAttribute(“className”,”styleClass”);

    所以使用时把以上两句都写上。

    四:创建文本输入元素

    Var button = document.createElement(“input”);

    //单行文本框、复选框、单选框、单选钮、按钮需要此属性区别

    Button.setAttribute(“type”,”button”);

    Document.getElementById(“formElement”).appendChild(button);

    五、向输入元素增加事件处理程序

    Var formElement=document.getElementById(“formElement”);

    //除IE外,所有浏览器可用

    formElement.setAttribute(“onclick”,”doFoo();”);

    //所有浏览器可用

    formElement.onclick=function(){doFoo();};

    六、创建单选钮

    如果是IE浏览器会存在uniqueID对象。

    If(document.uniqueID){

          //Internet Explorer

          Var radioButton=document.createElement(“<input type=’radio’ name=’radioButton’ value=’checked’>”);

    }else{

          //Standards Compliant

          Var radioButton=document.createElement(“input”);

          radioButton.setAttribute(“type”,”radio”);

          radioButton.setAttribute(“name”,”radioButton”);

          radioButton.setAttribute(“value”,”checked”);

    }

    七、insertRow,insertCell,deleteRow

    在IE中,table.insertRow()如果没有指定参数,则在表格后面添加行,默认参数位-1;如果在Firefox中,则一定要加参数,如:insertRow(-1)。
     
     

    发表于 @ 2008年01月16日 19:21:00|评论(loading...)|编辑

    新一篇: vs2008新特性 | 旧一篇: 在ASP.NET中实现自定义分页功能

    评论:没有评论。

    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © aaronbai