常见firefox不支持的JavaScript问题
<a href="#" onclick="ChildNode(this);">aaa</a>要改为
<a href="#" onclick="ChildNode(event);">aaa</a>
无法取得this对象,要用以下方法来取得。
function ChildNode(e)
{
var evt = e ? e : (window.event ? window.event : null); //此方法为了在firefox中的兼容
var node = evt.srcElement ? evt.srcElement : evt.target; //evt.target在火狐上才能识别用的。
selectNode = node.getAttribute("nodeId").toString();
}
nodeId属性不支持,要node.getAttribute("nodeId");
还有var+=elements[i].innerText在firefox中无识别,用elements[i].innerHTML来支持即可。
------------------------------------------------------------------------------------------------
//这是一个访问下拉框的方法,注意ele.option();中的圆括号firefox不支持,只能用[];才行。
var ele = document.getElementById('bizName');
idv = ele.option[ele.selectedIndex].title;
---------------------------------------------------------------------------
//在火狐中的地址栏输入:about:config,会出现火狐的参数配置设置,
---------------------------------------------------------------------------------
document.all在火狐中无法被识别,用document.getElementById,document.getElementByName等来替换即可。
----------------------------------------------------------------------------------------
//文件浏览的文本内容清理方法;unselectalbe:用于设置只读属性。on/off:两个值。
<input type="file" name="pic" id="pic" onchange="checkpic(this);" UNSELECTABLE="on"/>
function checkpic(here)
{
var reg_pic=/\w+(\.gif|\.jpg){1}/;
if(!reg_pic.test(here.value))
{
alert("");
here.outerHTML += "";//用于清除浏览框中的内容,here.value="";是无法执行的。IE支持这个方法
here.value = ""; //IE不支持这个属性,firefor却支持。
//在赋值时要注意outerHTML+=,value用=。
return;
}
}
//用来清除file中的内容;
<input type="file" id="file1"/><input type="button" onclick="addfile();"/>
function addfile(){
document.all('file1').select();
document.selection.clear()
}
----------------------------------------------------
//用来
相关文档:
这个问题很简单,主要有下面几个知识点:
(1) 取得时间:var d=new Date();var time=d.toLocaleString()
(2) 显示在网页上,假设写在一个<span>中,且该<span>的id为showTime:
document.getElementById("showTime").innerHTML ......
在网上找到在IE下操作IFrame内容的代码:
document.frames["MyIFrame"].document.getElementById("s").style.color="blue";
但是这在Firefox下无效。
所以,想到在Firefox下用FireBug来调试。经过调试发现在Firefox下可用以下代码来实现:
document.getElementById("MyIFr ......
方法一:
个人认为最好的方法.采用的是正则表达式,这是最核心的原理.
其次.这个方法使用了JavaScript 的prototype 属性
其实你不使用这个属性一样可以用函数实现.但这样做后用起来比较方便.
下面就来看看这个属性是怎么来用的.
返回对象类型原型的引用。
objectName.prototype
objectName 参数是对象的名称。 ......
如果你完全不懂,那么期望1-2周看完一遍拉倒....不用看的太仔细,后面再看到不懂的时候回头去看这些东西好了。
1. 前言和准备工作
这里不会介绍什么软件的用法一类的东西。如果觉得手写代码是在装的人可以出去了,谢谢。
首先你要有台电脑。然后它应该装着windows 和 IE。下面所谈到的代码 ......
/**
* 取得字符串的字节长度
*/
代码
function strlen(str)
{
var i;
var len;
len = 0;
for (i=0;i<str.length;i++)
{
if (str.charCodeAt(i)>255) len+=2; else len++;
}
return l ......