实现ajax时一些跨浏览器的js方法
来源:互联网 发布:双11淘宝红包口令 编辑:程序博客网 时间:2024/05/22 02:17
一. 向表中追加行
定义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)。
- 实现ajax时一些跨浏览器的js方法
- 兼容浏览器的js Ajax实现
- 一些常见跨浏览器方法的封装(basic.js)
- js浏览器检测的一些方法
- js windows.open 调用ajax时被一些浏览器阻止弹出窗体的解决方案
- 在Jquery实现Ajax和JS实现Ajax的方法
- 原生JS实现的AJAX方法、JSONP
- ajax跨浏览器的通用方法
- JS中操作IE浏览器的一些方法整理
- ajax的一些方法
- Ajax的一些方法
- JS 实现 ajax 异步 兼容浏览器
- 原生js实现ajax方法
- 原生js实现ajax方法
- js:浏览器跨域ajax变通实现 -- flash + js + crossdomain.xml
- JS的一些方法
- js 的一些方法
- JS判断浏览器的方法
- 带有事务集合整理--更新中
- HWQY油料价格计算存储过程(方便自己用发网上)
- 根据日志消息的内容进行日志输出
- c语言标准输入结束符
- C#基础学习日志===>数组<===
- 实现ajax时一些跨浏览器的js方法
- jsp标签jsp:setProperty用法
- 一些序列号
- 用8086汇编写的多线程任务的程序!
- ExecuteScalar为空的烦恼
- 时间服务器
- c#中邮件收发处理(POP3,IMAP,SMTP)
- 生命
- 常见./configure错误记录(Ubuntu)