
<body>
<div style="height: 20px;width: 20px;background: #666;" id="node">
</div>
<script>
// 使用原生JS
var node = documentgetElementById("node");
nodestylebackground = "black";
// 使用JQuery
var node = $("#node");
nodecss("background", "#111");
</script>
</body>
<html>
<head>
<script language="javascript">
function chk(){
var UserName;
var Pwd;
UserName=documentgetElementById("Bcuser")value;
Pwd=documentgetElementById("Bcpass")value;
if (UserNamelength<=0){
documentgetElementById("landout")styledisplay="none";
documentgetElementById("landover")styledisplay="block";
}
else{
documentgetElementById("landout")styledisplay="block";
documentgetElementById("landover")styledisplay="none";
}
}
function a(){
alert(Date());
}
</script>
</head>
<!--style="display: none" 登陆-->
<div class="top4" id="landout" style="display: black">
<form action="indexasp" method="post">
<table>
<tr>
<td id="td2">用户名称:</td>
<td id="td3"><input name="Bcuser" type="text" maxlength="15" id="Bcuser"/></td>
<td id="td4"><input name="Normal" type="image" src="images/dljpg" /></td>
</tr>
<tr>
<td id="td2">用户密码:</td>
<td id="td3"><input name="Bcpass" type="password" maxlength="15" id="Bcpass"/></td>
<td id="basicModal"><input name="basic" type="image" src="images/zcjpg" /></td>
</tr>
<tr>
<td> <input type="button" value="提交" onclick="chk()"></td>
</tr>
</table>
</form>
</div>
<!--style="display: none" 显示会员-->
<div class="top7" id="landover" style="display: none" >是这个意思吗</div>
</html>
采纳吧
block写成black了
,UserNamelength的length是不会小于0的,因为最小是0,所以判断条件改成UserNamelength<=0
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>test</title>
<style>
#one {
color: red;
width: 150px;
border: 1px solid blue;
}
#but {
color: blue;
width: 100px;
border: 1px solid red;
}
</style>
<script>
function cssrule(a, b) {
var a = a || 0;
var b = b || 0;
if (!!documentall) {
return documentstyleSheets[a]rules[b]style;
} else {
return documentstyleSheets[a]cssRules[b]style;
}
}
consolelog(cssrule()width);
consoledebug(cssrule(0, 1)width);
windowonload = function() {
var one = documentgetElementById("one");
var but = documentgetElementById("but");
butonclick = function() {
oneclassName = 'div2';
}
}
</script>
</head>
<body>
<div id="one">11111111111111</div>
<div id="but">22222222222222</div>
</body>
</html>
使用jQuery来获取元素的css比较方便。
举例如下:
html:
<div id="name">我是示例</div>css:
#name{width: 100px;
height: 100px;
}
jQuery:
$('#name')css('width');打印结果:
目前不存在兼容问题,常规浏览器都可以使用。
<div style="position:absolute;left:30px;">内联样式</div>如果要获取内嵌(style标签内的样式)或外部样式(link标签引入)的属性值。可以通过
currentStyle(for IE)或getComputedStyle(非IE)
以上就是关于JavaScript 如何获取和修改 div 中style中的值全部的内容,包括:JavaScript 如何获取和修改 div 中style中的值、Javascript 如何获取 修改 div style中的属性、javascript无法获取属性"style"的值 对象为null或未定义等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)