Archive

Posts Tagged ‘javaScript’

Javascript的IE和Firefox兼容解决方案汇总

December 25th, 2008

1:innerText

IE支持,FIREFOX不支持
解决办法:用innerHTML,2种浏览器都识别innerHTML

2:document.createElement
document.appendChild
在往表里插入行时
FIREFOX支持,IE不支持
解决办法:把行插入到TBODY中,不要直接插入到表

3:setAttribute(’’style”,”color:red;”)
FIREFOX支持(除了IE,现在所有浏览器都支持),IE不支持
解决办法:不用setAttribute(’’style”,”color:red”)
而用object.style.cssText = ”color:red;”(这写法也有例外)
最好的办法是上面种方法都用上,万无一失 ^_^
4:class
setAttribute(”class”,’’styleClass”)
FIREFOX支持,IE不支持(指定属性名为CLASS,IE不会设置元素的CLASS属性,相反只使用SETATTRIBUTE时IE自动识别CLASSNAME属性)
解决办法:
setAttribute(”class”,’’styleClass”)
setAttribute(”className”,’’styleClass”)
2种都用上(注:IE和FF都支持object.className) Read more…

undecided , ,

Firebug:罗列object的所有成员(JS/JSON)

July 24th, 2008

自己花了好大力气写了一个,可以展示JS对象无限层(理论上无限)子成员的方法.最近发现在firebug里这是很简单的.
在firebug控制台中输入console.dir(obj)就能够查看obj的全部成员了,也可以层层剥开.
想看console还有其他什么方法呢,只要 console.dir(console) 就可以了.
Read more…

Docu~ , , , , ,

js与flash双边通信(ExternalInterface类)

July 14th, 2008

js与flash双边通信 import flash.external.*; Read more…

Docu~ , ,

JS中数组的操作方法汇总

July 11th, 2008

javascript下对数组对象操作方法及实例 Read more…

Docu~ ,

IE和Firefox下event的差异

June 15th, 2008

如果在使用javascript的时候涉及到event处理,就需要知道event在不同的浏览器中的差异,因为javascript的事件模型有三种,它们分别是NN4、IE4+和W3C/Safari;这也造成了在不同的浏览器中处理event的差异,这里结合一些零碎的代码来说明如何做到event在 IE4+和Firefox下的正常工作。 Read more…

Docu~ , , ,

利用javascript中的原型实现继承

June 5th, 2008

常常说prototype,那javascript里prototype到底是什么呢?金山词霸一下就知道了,原型。
msdn中关于prototype的解释是 返回对象类型原型的引用。
这段话是非常tmd的抽象,太令人费解了。

后来看过了javascript权威指南一书后,我大概理解了其中的道理。 Read more…

Docu~ ,

input高级限制级用法

August 11th, 2007

input高级限制级用法

1.取消按钮按下时的虚线框
在input里添加属性值 hideFocus 或者 HideFocus=true

2.只读文本框内容
在input里添加属性值 readonly

3.防止退后清空的TEXT文档(可把style内容做做为类引用)

<input id=”oPersistInput” type=”text” />

4.ENTER键可以让光标移到下一个输入框

<input onkeydown=”if(event.keyCode==13)event.keyCode=9″ />

5.只能为中文(有闪动)

<input onkeyup=”value=value.replace(/[ -~]/g,”)” onkeydown=”if(event.keyCode==13)event.keyCode=9″ /> Read more…

Docu~ , , ,

JavaScript与Flash的通信

July 10th, 2007

当Flash置于HTML容器中时,经常会遇到AS与JS的通信问题,例如:JS能否调用AS中的变量、方法,AS能否调用JS中的变量、方法等等。答案是肯定的。随着技术的不断发展,解决方案也是多种多样的。
在我总结的HTML与FLASH之间的“静态”传值一文中提到了JS使用SetVariable方法来设置FLASH中的变量,kinglong认为此法已经过时。对此我表示同意,但上文重点毕竟不是在讨论JS与AS的通信,因此另外对AS与JS通信做一个个人总结,欢迎大家讨论。
实现JS跟AS的通信,目前可选方法比较多,但早期的方法在使用便捷和功能上都不是很完美,下面做一简要说明:
Read more…

Docu~ , ,

JS破解网页的限制:{禁止右击复制等}

May 12th, 2007

=禁止右击复制等

oncontextmenu=”return false” ondragstart=”return false” onselectstart =”return false” onselect=”document.selection.empty()” oncopy=”document.selection.empty()” onbeforecopy=”return false”onmouseup=”document.selection.empty()”

=完全破解
在地址栏输入执行以下一串代码就可以了
[code]

javascript:alert(document.onselectstart = document.onbeforecopy = document.oncontextmenu = document.onmousedown = document.onkeydown = function(){return true;});void(document.body.onmouseup=”); void(document.body.onselectstart=”); void(document.body.onmouseup=”); void(document.body.oncopy=”);

[/code]

个人计算机的话,放在收藏夹中更方便.
创建一个快捷方式,将其URL中 填写上这段破解代码,放在收藏夹里.到遇到有限制的网页,在收藏夹中点下这个就可以了[还能设置快捷键哦]

Docu~ ,

JS获取页面属性宽高

April 4th, 2007

JS准确获得页面、窗口高度及宽度

function getPageSize(){

var xScroll, yScroll;

if (window.innerHeight && window.scrollMaxY) {
xScroll = document.body.scrollWidth;
yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
} else { // Explorer Mac…would also work in Explorer 6 Strict, Mozilla and Safari
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}

var windowWidth, windowHeight;
if (self.innerHeight) { // all except Explorer
windowWidth = self.innerWidth;
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}

// for small pages with total height less then height of the viewport
if(yScroll < windowHeight){
pageHeight = windowHeight;
} else {
pageHeight = yScroll;
}

// for small pages with total width less then width of the viewport
if(xScroll < windowWidth){
pageWidth = windowWidth;
} else {
pageWidth = xScroll;
}

arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
return arrayPageSize;
}

Docu~ ,