顯示具有 jQuery Selector 標籤的文章。 顯示所有文章
顯示具有 jQuery Selector 標籤的文章。 顯示所有文章

星期四, 1月 03, 2013

[jQuery API] 指定selector不包含某些屬性

簡單的selector筆記

$("a:not([href*=word1],[href*=word2])").click(function() { //do something });

星期三, 7月 18, 2012

[jQuery API] 指定多重條件的selector (Multiple Attribute Selector)

有時候需要透過多個條件濾掉不需要的元素,
順便記錄一下,方便好查:)
[]區開就好,以下範例是指綁定No equal的


$("#manage_title").find("div[class!=manage_avatar][class!=manage_action]").click(function(){

});


Reference:
http://api.jquery.com/multiple-attribute-selector/

星期二, 5月 03, 2011

[jQuery] 快快樂樂jQuery-常用基礎語法篇

本文記錄常用的Jquery語法:

綁定多個id事件
$("#id1,#id2,#id3").click(function(){..........}); 

取得select的值:
$("#targetlist option:selected").text();

使用selector eq(index)設定select某一option被選取:
$("#selectElem option:eq(1)").attr("selected","true");

input的disalbed控制:
//disabled
$('#target').attr("disabled", true); 
//enable
$('#target').removeAttr("disabled"); 

取得元素 tag name
var elemName = $("#target").attr("tagName");

判斷元素是否存在
if ( $("#target").length > 0 ) {

...
...

}

display:block or none
$("#target").css("display","block");
$("#target").css("display","none");

偵測鍵盤,keycode請參考這篇
$("#target").keydown(function(event){
     console.log(event.keyCode);
 });

判斷Checkbox是否被選取
$("#target").attr("checked");//checked: true, unchecked: false

取得radio按鈕的值
$("input[name=gender]:checked").val()

星期三, 4月 07, 2010

[Jquery API] Disabled and Readonly Input

常常會到用input的disabled與readonly的控制。

$("#control").toggle( 

function () 
{ 
    $('#target').attr("disabled", true); 
}, 

function () 
{ 
    $('#target').removeAttr("disabled"); 
}

);


jQuery: Disabled and ReadOnly Inputs

星期日, 2月 07, 2010

[jQuery API] checkbox 控制記錄

老兄別再忘記這麼常用的東西了呀XD


如何透過jQuery選取所有的checkbox

$(document).ready(function(){
    $("#btnSelAll").click(function(){
        //alert('alert');
        $("input[type=checkbox]").attr("checked","checked");
    });
    $("#btnCancelAll").click(function(){
        $("input[type=checkbox]").attr("checked","");
    });
});

2012/09/11修正,應該改為true與false
  $("input[type=checkbox]").attr("checked",true);
  $("input[type=checkbox]").attr("checked",false);


如果元件為 disabled,反正也可置換成enabled
$("input:disabled[type=checkbox]").each(function(i,obj){
       ....
        });

取得checked的狀態

var currentCheck = $(this).attr("checked");

if(currentCheck == "checked"){
//check all

}
if(typeof(currentCheck) == 'undefined'){
//uncheck all

}

取得已選取checked狀態的checkbox


var $selectedCBs = $("#container").find("input:checked")

取得未選取checked狀態的checkbox
var $selectedCBs = $("#container").find("input:not(:checked)")

其他你感興趣的文章

Related Posts with Thumbnails