javascript获取iframe文档内容(兼容IE和Firefox)
在网上找到在IE下操作IFrame内容的代码:
document.frames["MyIFrame"].document.getElementById("s").style.color="blue";
但是这在Firefox下无效。
所以,想到在Firefox下用FireBug来调试。经过调试发现在Firefox下可用以下代码来实现:
document.getElementById("MyIFrame").contentDocument.getElementById("s").style.color="blue";
详细代码如下:
TestIFrame.htm:
<html>
<head>
<script type="text/javascript">
function f(){
var doc;
if (document.all){//IE
doc = document.frames["MyIFrame"].document;
}else{//Firefox
doc = document.getElementById("MyIFrame").contentDocument;
}
doc.getElementById("s").style.color="blue";
}
</script>
</head>
<body onload="f()">
<iframe id = "MyIFrame" name = "MyIFrame" src = "MyIFrame.htm" width = "100" height="100">
</body>
</html>
MyIFrame.htm:
相关文档:
每次用的时候都要找一遍资料,琢磨一遍语法,不胜其烦,终于下定决心把他们都记下来,一次性搞定,永绝后患!:)
一、什么是正则表达式?
简单地说,就是基于字符串的模式匹配工具。实际应用中包括字符串的查找、提取、替换等等。
二、基本语法
Javascript中的正则表达式的形式一 ......
(一)对象冒充
function A(name){
this.name = name;
this.sayHello = function(){alert(this.name+” say Hello!”);};
}
function B(name,id){
this.temp = A;
this.temp(name); &nbs ......
javascript中replace()
在javascript中,String的函数replace()简直太让人喜爱了。它灵活而强大的字符替换处理能力,让我不禁想向大家介绍它。
replace()最简单的算是能力就是简单的字符替换。示例代码如下:
<script language="javascript">
var strM = "javascript is a good script ......
一、声明字符串:
var normal_monkey = "I am a monkey!<br>";
document.writeln("Normal monkey " + normal_monkey);
var bold_monkey = normal_monkey.bold();
document.writeln("Bold monkey "&n ......