JQuery 小结

时间:2022-05-03
本文章向大家介绍JQuery 小结,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

1。文本框的改变事件,可使用propertychange,例如:

     $("#txtDataDate").bind("propertychange",function(){
      
             });

2。获取被选中RadioButton 的值

  var radio_value = $("input[@type=radio][checked]").val(); 

3。下拉列表的改变事件,以及获得选中选项的值

 $("#下拉列表").change(function() {
  //获得选中项的value值        
 var  select = $(this).val();
  var checkText=$("#select_id").find("option:selected").text();  //获取Select选择的Text


                        
     }).change();

4。获取下拉列表DropDownList选中的值

var ddl = $("#ddlDiaryType option:selected").text();//下拉别表 

 5。Jquery绑定同一事件时,如要只执行一个事件,需要用  $("#txt").unbind();方法卸载事件,例如:

   $("#ddlType").change(function () {
                var now = new Date();
                var ADateNow = now.getYear() + "-" + (now.getMonth() + 1);
                var select = $(this).val();
                $("#txtStartTime").unbind("focus");
                $("#txtEndTime").unbind("focus");
                if (select == "月") {
                    var ADate = ADateNow;
                    $("#txtStartTime").focus(function () { WdatePicker({ isShowClear: false, readOnly: true, skin: 'whyGreen', dateFmt: 'yyyy-MM' }); }).val(ADate);
                    $("#txtEndTime").focus(function () { WdatePicker({ isShowClear: false, readOnly: true, skin: 'whyGreen', dateFmt: 'yyyy-MM' }); }).val(ADate);
                }
                else {
                    ADate = ADateNow + "-" + now.getDate();
                    $("#txtStartTime").focus(function () { WdatePicker({ isShowClear: false, readOnly: true, skin: 'whyGreen', dateFmt: 'yyyy-MM-dd' }); }).val(ADate);
                    $("#txtEndTime").focus(function () { WdatePicker({ isShowClear: false, readOnly: true, skin: 'whyGreen', dateFmt: 'yyyy-MM-dd' }); }).val(ADate);
                }

            }).change();