JQuery 获取和编辑页面元素

来源:互联网 发布:松江主机编程 编辑:程序博客网 时间:2024/06/05 15:46

修改页面元素 <div> 和 <font> 源码如下:

<html>  
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">  
</head>  
 
<script language="JavaScript">  
function IT(){  
    f1.innerText="innerText";  
}  
function IH(){  
    f1.innerHTML="<H1>innerHTML</H1>";  
}  
function OT(){  
    f1.outerText="outerText";  
}  
function OH(){  
    d1.outerHTML="<H2>outerHTML</H2>";  
}  
</script>  
 
<body>  
<div id="d1"><font id="f1" size="5" color="blue"></font></div>  
<input type="button" value="innerText" onclick="IT()">  
<input type="button" value="innerHTML" onclick="IH()">  
<input type="button" value="outerText" onclick="OT()">  
<input type="button" value="outerHTML" onclick="OH()">  
</body>  
</html>  

获取页面元素 <p> 源码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>

<p id="demo">单击按钮获取按钮元素的文本内容</p>
<button onclick="myFunction()">点我</button>
<script>
function myFunction(){
    var x=document.getElementById("demo");  
    alert(x.innerHTML);
}
</script>
<p><strong>注意:</strong> Internet Explorer 8 及更早版本不支持textContent属性。</p>

</body>
</html>
0 0