怎么不能像例子一樣?
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
??? <head>
??????? <title>toggle()方法綁定多個函數(shù)</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()方法綁定多個函數(shù)</h3>
??????? <input id="btntest" type="button" value="點(diǎn)一下我" />
??????? <div>我是動態(tài)顯示的</div>
?????? ?
??????? <script type="text/javascript">
??????????? $(function () {
??????????????? $("div").bind("click", function () {
??????????????????? $("div").toggle(function(){
??????????????????????? $(this).html("123");
??????????????????? },function(){
??????????????????????? $(this).html("456");
??????????????????? });
??????????????? })
??????????? });
??????? </script>
??? </body>
</html>
2016-03-23
可以實(shí)現(xiàn)例子的效果,只是你把重點(diǎn)放在了按鈕上,所以自然就沒有發(fā)現(xiàn)效果,首先你把按鈕綁定了點(diǎn)擊事件,你點(diǎn)按鈕時,它只是激發(fā)了下面展示區(qū)的函數(shù),你在點(diǎn)按鈕是看不到效果的,如果你在點(diǎn)擊完按鈕后,在點(diǎn)擊展示區(qū)域,切換的效果就出現(xiàn)了,是的,只有在點(diǎn)擊完按鈕,激活展示區(qū),在點(diǎn)擊展示區(qū)才會出現(xiàn)切換效果。如果你一直點(diǎn)擊按鈕,抱歉,你能看到的是毫無變化(但其實(shí)是有變化的,就是激活了toggle函數(shù)),如果你不點(diǎn)擊按鈕,點(diǎn)擊展示區(qū)的話,一點(diǎn)效果都沒有。
2016-03-17
jquery版本不同 ,會導(dǎo)致效果不能實(shí)現(xiàn).可以采用如下的辦法,這是在Jquery官網(wǎng)上的方法
$("#btn").click(function(){
? ?$(this).next().toggle();
});
簡單,并且能夠?qū)崿F(xiàn):當(dāng)點(diǎn)擊時顯示,再次點(diǎn)擊時隱藏。
2016-02-23
再對照了例子,bind()方法下面的toggle()不能實(shí)現(xiàn)例子的效果
2016-02-23
為啥是?$("div").bind("click", function () {不是$("#btntest").bind("click", function () {