当dropdownlist selectedvalue时触发jquery函数

时间:2012-11-06 04:32:31

标签: jquery asp.net function drop-down-menu selectedvalue

我有一个jQuery动画函数,如果我的下拉列表的selectedvalue是X,我想调用它

       <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 个答案:

答案 0 :(得分: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;

   });
});

答案 1 :(得分:0)

DropDown id - &gt; 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;
  });
});