Memo: Jquery 常忘語句

1.頁面加載執行語句

		    jQuery(document).ready(function ($) {
		     //   $(".tabs").tabs();
 
		    });

2.  ajax  交互並渲染頁面的combobox 控件

	       function foo(product_id)
	       {     
	   	        $.ajax({     
	   	        type: "GET",     
	   	        url: "getFoo?productname="+product_id,     
	   	        dataType:   "json",   
                        //async:false,//取消異步請求
	   	        success: function(data,textStatus){     
	   	            // display    
	   	          
	   	     
	               var bnSelect = document.getElementById("mycombobox");
	                   for ( var i=bnSelect.options.length-1; i>-1; i-- )
	                   {     
	                   	bnSelect[i] = null;
	                   }     
	               if(data.length > 0) {
	                         $("#mycombobox").show(); 
			   	        for(i=0;i<data.length;i++)
			   	        {     
			   	                bnSelect.options[i] = new Option();     
			   	                bnSelect.options[i].text = data[i].label;     
			   		            bnSelect.options[i].value = data[i].value;     
			            }   
			   	     bnSelect.options[0].selected="selected";// default select the first one
	   	        	}
	   	  
	           }// end of success....func    
	   	    })   //end of ajax
	      }//end of func

3.  隱藏/顯示 div 或 tr td 控件

                               $('#myid').css("display", "none");//hide this.

                              $('#myid').css("display", "");//show this.    

4. set requried 域, remove required

	    	  var all_row=$("tr[name^='tr_']")
	    	  all_row.prop('required',true);
                  all_locale_row.removeAttr('required'); // remove required 
遇到一個異常報“An invalid form control with name=xxx is not focusable” ,通常是因爲設置了required 域後的控件被隱藏的緣故,不過在實際中,遇到該異常提示的name與實際出問題的控件名字不一致的情況……不曉得爲什麼
5.  set  text

對<p>:

	    	var msg = "Must select target locales !";
	   	$('#my_p').text(msg);

6. get value for  multi-select

             var targeted = $('#selectTarget').val();
              if (targeted == null)
              {
                 // do something
              }
              for(var i =0;i<targeted.length;i++)
            {
                  var locale_r=$('#tr_'+targeted[i]);
                 locale_r.css("display", "");//show this.
                 locale_r.prop('required',true);
            }


To be continued....


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章