• Example010实现浏览器兼容改内容的函数,自写


    <!-- 实例010实现浏览器兼容改内容的函数 -->
    <!DOCTYPE html>
    <html lang="en">
    <head>
    	<meta charset="UTF-8">
    	<title>实例010实现浏览器兼容改内容的函数</title>
    </head>
    <body>
    <!-- 内容(通常使用的四个属性) a div b h1 input用value
    	innerText只有IE好用,非IE用(textContent),不兼容
    	属性可以改值,也可以取值 -->
    	<div id="test" onclick="change()">你好!</div>
    	<script>
    		var obj = document.getElementById("test");
    		function change() {
    			// 可以兼容的改值
    			// intext(obj,"handsomehan");
    			// 可以兼容的获取值
    			// alert(intext(obj));
    			//obj.innerHTML = "<h1>我是handsomehan</h1>" //innerHTML这个是兼容的;
    			alert(obj.innerHTML);
    			alert(obj.outerHTML);
    		}
    
    		function intext(name,value) {
    			//如何区分IE和非IE,IE中的document中有all这个属性
    			if (document.all){
    				if (typeof(value) == "undefined") {
    					return name.innerText;
    				}else {
    					name.innerText = value;
    				} 
    			} else {
    				if (typeof(value) == "undefined") {
    					return name.textContent;
    				} else {
    					name.textContent = value;
    				}
    			}
    		}
    	</script>
    </body>
    </html>
    

      

  • 相关阅读:
    Windows 7 SP1无人值守自动应答文件制作
    Ubuntu GNOME单击任务栏图标最小化设置
    NOIP2017题解
    NOIP2017游记
    大模拟1.0
    奇袭
    礼物
    找硬币
    Fiolki
    SQLserver Delete from where 与Oracle delete from where 的差异
  • 原文地址:https://www.cnblogs.com/handsomehan/p/5366145.html
Copyright © 2020-2023  润新知