900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > 原生js实现改变随意改变div属性style的名称和值的结果【javascript】

原生js实现改变随意改变div属性style的名称和值的结果【javascript】

时间:2020-09-23 00:38:44

相关推荐

原生js实现改变随意改变div属性style的名称和值的结果【javascript】

web前端|js教程

div属性,style名称和值

web前端-js教程

一些简单的例子,用原生js和jQuery实现随意改变div属性,和重置。代码如下:

jsp导航网站源码,ubuntu qt读取文件,java爬虫拒绝301,PHP管材,Seo搜索指数lzw

函数传参,改变Div任意属性的值

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;}

函数传参,改变Div任意属性的值

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;}

/*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部分实现

$(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");

})

})

视频点播系统php源码,vscode运行一闪而过,北通 ubuntu,配置tomcat的文件是,爬虫 图片 实例,ajax传值到php,SEO优化不包括的内容是lzw

php在线报名系统源码,2400g ubuntu,tomcat线程数为X,爬虫与solr,东莞php网站制作,宁夏seo搜索引擎优化多少钱lzw

在上方输入框输入”属性名”及”属性值”,点击确定按钮查看效果。

$(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”);

})

})

在上方输入框输入”属性名”及”属性值”,点击确定按钮查看效果。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。