亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

請問這段代碼有什么問題,這樣連起來寫有問題?

<!DOCTYPE html>
<html>
??? <head>
??????? <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
??????? <title>jQuery動畫特效</title>
??????? <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>
??????? <style>
??????????? div{
??????????????? position:relative;
??????????????? margin:5px;
??????????????? width:100px;
??????????????? height:100px;
??????????????? border:2px solid #999;
??????????????? background:#f60;
?????????????? ?
??????????????? }
??????? </style>
??? </head>
??? <body>
??????? <button class="i">按鈕1--左移動</button>
??????? <button class="j">按鈕2--右移動</button>
??????? <div>hello world</div>
??????? <script type="text/javascript">
??????????? $(function)(){
??????????????? $(".i").bind("click",function(){
??????????????????? $("div").animate({
??????????????????????? left:"+=50px" },1000,function(){
??????????????????? $(".j").bind("click",function(){
??????????????????????? $("div").animate({
??????????????????????? right:"-=50" },1000,function()
??????????????????????? {$("div").html(執行結束!)})
??????????????????? })})})}
????????????????????? ?
??????? </script>
??? </body>
</html>

正在回答

3 回答

你的錯誤太多了,我在你的代碼基礎上給你改的,你自己對比看一下。注意代碼書寫規范,你的寫的有點亂。

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

一個愛狗的男生 提問者

我 是把 animate的第三個callback 綁定第二個事件里面了。好像并不能實現。
2016-04-14 回復 有任何疑惑可以回復我~
#2

漩渦鳴人007 回復 一個愛狗的男生 提問者

你可以把 callback執行的操作寫在外面,然后在animate中直接調用
2016-04-14 回復 有任何疑惑可以回復我~
#3

漩渦鳴人007 回復 一個愛狗的男生 提問者

$(".i").bind("click",function(){ $("div").animate({left:"-=50px" },1000,callBack) }); $(".j").bind("click",function(){ $("div").animate({left:"+=50px" },1000,callBack) }); function callBack(){//寫成函數,直接調用 $("div").html("執行結束!") }
2016-04-14 回復 有任何疑惑可以回復我~

<!DOCTYPE html>

<html>

? ? <head>

? ? ? ? <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

? ? ? ? <title>jQuery動畫特效</title>

? ? ? ? <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>

? ? ? ? <style>

? ? ? ? ? ? div{

? ? ? ? ? ? ? ? position:relative;

? ? ? ? ? ? ? ? margin:5px;

? ? ? ? ? ? ? ? width:100px;

? ? ? ? ? ? ? ? height:100px;

? ? ? ? ? ? ? ? border:2px solid #999;

? ? ? ? ? ? ? ? background:#f60;

? ? ? ? ? ? ? ? left:200px;

? ? ? ? ? ? ? ? }

? ? ? ? </style>

? ? </head>

? ? <body>

? ? ? ? <button class="i">按鈕1--左移動</button>

? ? ? ? <button class="j">按鈕2--右移動</button>

? ? ? ? <div>hello world</div>

? ? ? ? <script type="text/javascript">

? ? ? ? ? ? $(function(){

? ? ? ? ? ? ? ? $(".i").bind("click",function(){

? ? ? ? ? ? ? ? ? ? $("div").animate({left:"-=50px" },1000)

});

$(".j").bind("click",function(){

$("div").animate({left:"+=50px" },1000,function(){

$("div").html("執行結束!")

})

});

})

? ? ? ? ? ? ? ? ? ? ? ?

? ? ? ? </script>

? ? </body>

</html>


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

舉報

0/150
提交
取消
jQuery基礎課程
  • 參與學習       154733    人
  • 解答問題       7289    個

加入課程學習,有效提高前端開發速度

進入課程

請問這段代碼有什么問題,這樣連起來寫有問題?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號