為什么不行啊 求指導(dǎo)啊
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<title>挑戰(zhàn)題</title>
</head>
<body>
? ?<ul>
? ? ? ?<li>111</li>
? ? ? ?<li>222</li>
? ? ? ?<li>333</li>
? ? ? ?<li>444</li>
? ? ? ?<li style="display:none" class="hidden">555</li>
? ? ? ?<li ?style="display:none" class="hidden">666</li>
? ? ? ?<li>777</li>
? ?</ul>
<input class='button' type='button' value='更多' onclick='click()'>
</body>
<script type="text/javascript">
? ?function click(){
? ? ? ?if($(".button").html()=='更多'){
? ? ? ? ?$('.hidden').css("display","block");
? ? ? ? ?$(".button").html("簡化");
? ? ? ?}else{
? ? ? ? ?$(".button").html("更多");
? ? ? ?}
? ?}
</script>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<title>挑戰(zhàn)題</title>
</head>
<body>
? ?<ul>
? ? ? ?<li>111</li>
? ? ? ?<li>222</li>
? ? ? ?<li>333</li>
? ? ? ?<li>444</li>
? ? ? ?<li style="display:none" class="hidden">555</li>
? ? ? ?<li ?style="display:none" class="hidden">666</li>
? ? ? ?<li>777</li>
? ?</ul>
<input class='button' type='button' value='更多' onclick='click()'>
</body>
<script type="text/javascript">
? ?function click(){
? ? ? ?if($(".button").html()=='更多'){
? ? ? ? ?$('.hidden').css("display","block");
? ? ? ? ?$(".button").html("簡化");
? ? ? ?}else{
? ? ? ? ?$('.hidden').css("display","none");
? ? ? ? ?$(".button").html("更多");
? ? ? ?}
? ?}
</script>
</html>
2016-04-05
不能正常運行有2個問題:
函數(shù)名不能用click,這與js自身的click方法重名了。
讀取或修改表單元素的value值應(yīng)該用.val(),.html()是用來讀取元素的HTML內(nèi)容(如果你用.html(),你就會發(fā)現(xiàn)value值沒有變化)。
2016-04-05
input元素的值是由value屬性控制,你要用val()方法修改值而不是html()
2016-04-05
It sounds bad.Maybe the code should be $(".button").text() or .val().