2012-11-06 20 views
1

我有一個jQuery的動畫,我想打電話,如果我的下拉列表中的SelectedValue是XjQuery函數發射時下拉列表的SelectedValue

 <script> 
    $(function() { 
     var state = true; 
     ($("#button").click)(function() { 
      if (state) { 
       $("#effect").animate({ 
        backgroundColor: "#aa0000", 
        color: "#fff", 
        width: 500 
       }, 1000); 
        } else { 
       $("#effect").animate({ 
        backgroundColor: "#fff", 
        color: "#000", 
        width:500 

       }, 1000); 
      } 
      state = !state; 
     }); 
    }); 
+2

這裏有很多格式化問題,就像一個'.click'事件,而不是'.change()'一個下拉列表,就像你說的那樣。 –

+0

我的確同意事件應該寫在滴水清單上而不是按鈕 –

+0

這裏是一個例子,它可以幫助你的
http://stackoverflow.com/questions/4910795/run-jquery-function-on-drop-向下變 –

回答

0

功能你可以嘗試這樣

jQuery(document).ready(function(){ 
    var state = true; 
    $("#otherCatches").change(function() { 
     if (state) { 
      $("#effect").animate({ 
       backgroundColor: "#aa0000", 
       color: "#fff", 
       width: 500 
      }, 1000); 
       } else { 
      $("#effect").animate({ 
       backgroundColor: "#fff", 
       color: "#000", 
       width:500 

      }, 1000); 
     } 
     state = !state; 

    }); 
}); 
0

下拉id - > ddlDropDown

 $(document).ready(function(){ 
      var state = true; 
     $("#ddlDropDown").change(function() { 
      if ($("#ddlDropDown").val()=="X") { //Checking if value is X 
       $("#effect").animate({ 
        backgroundColor: "#aa0000", 
        color: "#fff", 
        width: 500 
        }, 1000); 
       } else { 
       $("#effect").animate({ 
       backgroundColor: "#fff", 
       color: "#000", 
       width:500 

     }, 1000); 
     } 
     state = !state; 
    }); 
});