色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

原生js和jQuery隨意改變div屬性style的名稱和值

一些簡單的例子,用原生js和jQuery實(shí)現(xiàn)隨意改變div屬性,和重置。代碼如下:

<!DOCTYPE html><html><head><meta charset="utf-8"/><title>函數(shù)傳參,改變Div任意屬性的值</title><style type="text/css">body,p{margin:0;padding:0;}body{color:#333;font:12px/1.5 Tahoma;padding-top:10px;}#outer{width:300px;margin:0 auto;}p{margin-bottom:10px;}button{margin-right:5px;}label{width:5em;display:inline-block;text-align:right;}input{padding:3px;font-family:inherit;border:1px solid #ccc;}#div1{color:#fff;width:180px;height:180px;background:#000;margin:0 auto;padding:10px;}</style><script type="text/Javascript" src="js/jquery-1.4.2.min.js"></script><script type="text/Javascript"><!DOCTYPE html><html><head><meta charset="utf-8"/><title>函數(shù)傳參,改變Div任意屬性的值</title><style type="text/css">body,p{margin:0;padding:0;}body{color:#333;font:12px/1.5 Tahoma;padding-top:10px;}#outer{width:300px;margin:0 auto;}p{margin-bottom:10px;}button{margin-right:5px;}label{width:5em;display:inline-block;text-align:right;}input{padding:3px;font-family:inherit;border:1px solid #ccc;}#div1{color:#fff;width:180px;height:180px;background:#000;margin:0 auto;padding:10px;}</style><script type="text/Javascript" src="js/jquery-1.4.2.min.js"></script><script type="text/Javascript">/*var changeSytle = function (elem,name,value){elem.style[name] = value;}window.onload = function (){var oDiv = document.getElementById("div1");var oBtn = document.getElementsByTagName("button");var oInput = document.getElementsByTagName("input");oBtn[0].onclick = function (){changeSytle (oDiv,oInput[0].value,oInput[1].value)} ,oBtn[1].onclick = function (){oDiv.removeAttribute("style");}} */原生js部分實(shí)現(xiàn)$(function(){$("button:first").click(function(){var styleName= $("#outer").find("input:first").val();var styleVal = $("#outer").find("input:last").val();$("#div1").css(styleName,styleVal);})$("button:last").click(function(){$("#div1").removeAttr("style");})})</script></head><body><div id="outer"><p><label>屬性名:</label><input type="text" value="background" name="styleName" /></p><p><label>屬性值:</label><input type="text" value="blue" name="val" /></p><p><label></label><button>確定</button><button>重置</button></p></div><div id="div1">在上方輸入框輸入"屬性名"及"屬性值",點(diǎn)擊確定按鈕查看效果。</div></body></html>$(function(){$("button:first").click(function(){var styleName= $("#outer").find("input:first").val();var styleVal = $("#outer").find("input:last").val();$("#div1").css(styleName,styleVal);})$("button:last").click(function(){$("#div1").removeAttr("style");})})</script></head><body><div id="outer"><p><label>屬性名:</label><input type="text" value="background" name="styleName" /></p><p><label>屬性值:</label><input type="text" value="blue" name="val" /></p><p><label></label><button>確定</button><button>重置</button></p></div><div id="div1">在上方輸入框輸入"屬性名"及"屬性值",點(diǎn)擊確定按鈕查看效果。</div></body></html>

JavaScript技術(shù)原生js和jQuery隨意改變div屬性style的名稱和值,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 正蓝旗| 新河县| 浏阳市| 桐城市| 天津市| 耒阳市| 新丰县| 罗田县| 缙云县| 峨山| 固始县| 丽水市| 郸城县| 辰溪县| 卓尼县| 文成县| 和平县| 尖扎县| 左贡县| 双柏县| 汉寿县| 丰顺县| 深圳市| 仲巴县| 广汉市| 泰顺县| 延长县| 来凤县| 贡山| 万山特区| 江安县| 张家港市| 安塞县| 房产| 新建县| 秭归县| 赤壁市| 霞浦县| 嘉善县| 突泉县| 平泉县|