點擊按鈕沒有反應?不能切換div里面的文字 如果只保留兩個就可以實現切換
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
? ? <head>
? ? ? ? <title>toggle()方法綁定多個函數</title>
? ? ? ? <script src="http://libs.baidu.com/jquery/1.8.2/jquery.js" type="text/javascript"></script>
? ? ? ? <link href="style.css" rel="stylesheet" type="text/css" />
? ? </head>
? ? <body>
? ? ? ? <h3>toggle()方法綁定多個函數</h3>
? ? ? ? <input id="btntest" type="button" value="點一下我" />
? ? ? ? <div>我是動態顯示的</div>
? ? ? ??
? ? ? ? <script type="text/javascript">
? ? ? ? ? ? $(function () {
? ? ? ? ? ? ? ? $("#btntest").bind("click", function () {
? ? ? ? ? ? ? ? ? ? $("div").toggle(function(){
? ? ? ? ? ? ? ? ? ? ? ? $(this).text("123");
? ? ? ? ? ? ? ? ? ? },function(){
? ? ? ? ? ? ? ? ? ? ? ? $(this.text("456");
? ? ? ? ? ? ? ? ? ? });
? ? ? ? ? ? ? ? })
? ? ? ? ? ? });
? ? ? ? </script>
? ? </body>
</html>
2016-07-20
$("#btntest").toggle(
? ? ? ? ? ? ? ? ? ? ? ? ? ? function(){
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? $("div").html("123");
? ? ? ? ? ? ? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ? ? ? ? ? ? ? function(){
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? $("div").html("456");
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? )
toggle()默認綁定的就是單擊事件
2016-07-15
$(this).text("456"); ?你括號少打了個