1 /*傳入下拉select標簽*/ 2 function get_selected(mslt_employees) { 3 var emplo =mslt_employees.multiselect("getChecked").map(function () { 4 return this.value; 5 }).get(); 6 7 if (isArray(emplo)) {//判斷是否數組 8 list_str = emplo.join(",");//數組轉為逗號分隔的字符串 9 } else { 10 var list_str = emplo; 11 } 12 return list_str; 13 }
//判斷是否數組的方法 isArray = function (source) { return '[object Array]' == Object.prototype.toString.call(source); };
//傳入標簽 var department = get_selected($("#mslt_department")); //$(this)是一個JQuery對象 var department = get_selected($(this));
jQuery中this與$(this)的區別
//這里的this其實是一個Html 元素(textbox),textbox有text屬性 $("#textbox").hover( function() { this.title = "Test"; }, fucntion() { this.title = "OK”; } ); //$(this)是一個JQuery對象,而jQuery對象沒有title 屬性,JQuery擁有attr()方法可以get/set DOM對象的屬性 function() { $(this).attr(’title’, ‘Test’); } // 錯誤的寫法 $("#textbox").hover( function() { $(this).title = "Test"; }, function() { $(this).title = "OK"; } );