怎样实现每点击一下按钮div宽度就减小5px
3个回答
展开全部
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<div style="border: 1px solid red;height:100px;width:100px;" id="d1"></div>
<div>
<input type="button" onclick="small()"; value="缩小">
</div>
</body>
<script type="text/javascript">
var w=100;
function small(){
w=w-5;
document.getElementById("d1").style.width=w;
}
</script>
</html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<div style="border: 1px solid red;height:100px;width:100px;" id="d1"></div>
<div>
<input type="button" onclick="small()"; value="缩小">
</div>
</body>
<script type="text/javascript">
var w=100;
function small(){
w=w-5;
document.getElementById("d1").style.width=w;
}
</script>
</html>
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>5_div改变样式</title>
<style>
#div1 {
width: 200px;
height: 200px;
background: red;
}
</style>
<script>
function setStyle(name, value) {
oDiv = document.getElementById('div1');
//第一种操作属性的方式
// oTxt.value = 'asidjk';
//第二种操作属性的方式
oDiv.style[name] = value;
if (oDiv.style[name] == '') {
oDiv.style.background = 'red';
oDiv.style.width = '200px';
oDiv.style.height = '200px';
}
}
var w = 200;
function small() {
w = w - 5;
document.getElementById("div1").style.width = w + 'px';
document.getElementById("div1").style.height = w + 'px';
}
</script>
</head>
<body>
<input type="button" value="变窄" onclick="small()" />
<input type="button" value="变高" onclick="setStyle('height','400px')" />
<input type="button" value="变绿" onclick="setStyle('background','green')" />
<input type="button" value="还原" onclick="setStyle('','')" />
<div id="div1"></div>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>5_div改变样式</title>
<style>
#div1 {
width: 200px;
height: 200px;
background: red;
}
</style>
<script>
function setStyle(name, value) {
oDiv = document.getElementById('div1');
//第一种操作属性的方式
// oTxt.value = 'asidjk';
//第二种操作属性的方式
oDiv.style[name] = value;
if (oDiv.style[name] == '') {
oDiv.style.background = 'red';
oDiv.style.width = '200px';
oDiv.style.height = '200px';
}
}
var w = 200;
function small() {
w = w - 5;
document.getElementById("div1").style.width = w + 'px';
document.getElementById("div1").style.height = w + 'px';
}
</script>
</head>
<body>
<input type="button" value="变窄" onclick="small()" />
<input type="button" value="变高" onclick="setStyle('height','400px')" />
<input type="button" value="变绿" onclick="setStyle('background','green')" />
<input type="button" value="还原" onclick="setStyle('','')" />
<div id="div1"></div>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
onclick事件,点击这个div就减少这个div属性的宽度啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询