最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

原生js實(shí)現(xiàn)改變隨意改變div屬性style的名稱和值的結(jié)果

 更新時(shí)間:2013年09月26日 17:48:20   作者:  
在本文將為大家介紹下如何用原生js和jQuery實(shí)現(xiàn)隨意改變div屬性,和重置,具體實(shí)現(xiàn)如下,感興趣的朋友可以參考下,希望對(duì)大家有所幫助
一些簡單的例子,用原生js和jQuery實(shí)現(xiàn)隨意改變div屬性,和重置。代碼如下:
復(fù)制代碼 代碼如下:

<!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>

相關(guān)文章

最新評(píng)論

郎溪县| 长治市| 女性| 古蔺县| 麟游县| 都安| 尚义县| 淄博市| 建平县| 桐柏县| 察雅县| 化隆| 上林县| 建湖县| 郯城县| 翁源县| 四会市| 上林县| 绥宁县| 阳春市| 隆子县| 周至县| 普安县| 镇远县| 秭归县| 浦东新区| 鞍山市| 南和县| 兴义市| 岐山县| 雅安市| 巴林左旗| 郴州市| 米泉市| 游戏| 乌审旗| 五河县| 阿坝| 柘荣县| 民勤县| 温州市|