重置函数有对话框,但是点击确定后不起作用。

来源:4-1 编程挑战

黯夜旋风

2015-12-01 15:02

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>mission</title>

<style type="text/css">

body {

font-size: 12;

}

#txt {

height: 333px;

width: 500px;

border: red solid 2px;

padding: 5px;

}

p {

line-height: 20px;

text-indent: 2em;

}

</style>

</head>

<body>

<h1 id="demo1">JavaScript</h1>


<div id="txt">

<h5>我也不知道这要干嘛</h5>

<p>7.Your rejection taught me courage.</p>

<p>8.Whether you view me as a hero or a villain,</p>

<p>9.please know that I poured every emotion,every bit of passion and my entire self into being a Laker,</p>

</div>

<form>

<input type="button" value="改变颜色" onclick="changeColor()" />

<input type="button" value="改变宽高" onclick="ser.changeSize()" />

<input type="button" value="隐藏内容" onclick="ser.hideText()" />

<input type="button" value="显示内容" onclick="ser.showText()" />

<input type="button" value="取消设置" onclick="ser.OffSet()" />

</form>


<script type="text/javascript">

var txt = document.getElementById("txt");


function changeColor() {

txt.style.color = "goldenrod";

txt.style.backgroundColor = "blanchedalmond";

}

var ser = {

changeSize: function() {

txt.style.width = "600px";

txt.style.height = "200px";

},

hideText: function() {

txt.style.display = "none";

},

showText: function() {

txt.style.display = "block";

},

OffSet: function() {

var message = confirm("你确定要重置所有设置么?");

if (message == true) {

txt.removeAttribute('style');

}

}

}

</script>

</body>

</html>


写回答 关注

2回答

  • 黯夜旋风
    2015-12-01 16:45:37

    谢了,可能是浏览器问题,开始用的Google不行,换了IE就可以。

  • Perona
    2015-12-01 15:36:44

    代码没问题呀。运行也可以的哒。

JavaScript入门篇

JavaScript做为一名Web工程师的必备技术,本教程让您快速入门

739817 学习 · 9566 问题

查看课程

相似问题