为了账号安全,请及时绑定邮箱和手机立即绑定

为什么点击更改样式没有变化啊

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>className属性</title>
<style>
    body{ font-size:16px;}
    .one{
		border:1px solid #eee;
		width:230px;
		height:50px;
		background:#ccc;
		color:red;
    }
	.two{
		border:1px solid #ccc;
		width:230px;
		height:50px;
		background:#9CF;
		color:blue;
	}
	</style>
</head>
<body>
    <p id="p1" > JavaScript使网页显示动态效果并实现与用户交互功能。</p>
    <input type="button" value="添加样式" onclick="add()"/>
	<p id="p2" class="one">JavaScript使网页显示动态效果并实现与用户交互功能。</p>
    <input type="button" value="更改外观" onclick="modify()"/>

	<script type="text/javascript">
	   function add(){
	      var p1 = document.getElementById("p1");
	      function.modifyclass(){
	          p1.className="类名为one";
	      }
	   }
	   function modify(){
	      var p2 = document.getElementById("p2");
	      function.modifyclass(){
	          p2.className="类名为two";
	      }
	   }
	</script>
</body>
</html>


正在回答

3 回答

把类名为三个字删除就行了,className是改成”one“和”two“,不是”类名为one“

0 回复 有任何疑惑可以回复我~
#1

Flzz 提问者

改了也不行
2017-07-29 回复 有任何疑惑可以回复我~
#2

impeldown_0 回复 Flzz 提问者

还有一个问题,function modifyclass(){}这段删除,也就是直接改成p1.className="two";就行了,或者你在modify函数里加入调用modifyclass()指令才能执行,因为你在一个函数里定义了另一个函数但是并没有调用它,所以不会执行的。
2017-08-08 回复 有任何疑惑可以回复我~
#3

Flzz 提问者

非常感谢!
2017-08-08 回复 有任何疑惑可以回复我~

用这个你就明白这个空格来自哪里了

vhaouietaqslnok

0 回复 有任何疑惑可以回复我~

<!DOCTYPE HTML>
<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
   <title>className属性</title>
   <style>
       body{ font-size:16px;}
       .one{
           border:1px solid #eee;
           width:230px;
           height:50px;
           background:#ccc;
           color:red;
       }
       .two{
           border:1px solid #ccc;
           width:230px;
           height:50px;
           background:#9CF;
           color:blue;
       }
   </style>
</head>
<body>
<p id="p1" > JavaScript使网页显示动态效果并实现与用户交互功能。</p>
<input type="button" value="添加样式" onclick="add()"/>
<p id="p2" class="one">JavaScript使网页显示动态效果并实现与用户交互功能。</p>
<input type="button" value="更改外观" onclick="modify()"/>

<script type="text/javascript">
   function add(){
       var p1 = document.getElementById("p1");
       function modifyclass(){
           p1.className="one";
       }
       modifyclass();
   }
   function modify(){
       var p2 = document.getElementById("p2");
       function modifyclass(){
           p2.className="two";
       }
       modifyclass();
   }
</script>
</body>
</html>

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

为什么点击更改样式没有变化啊

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信