2009-12-21 84 views

回答

1
$(this).attr("type"); 

例如:

$(document).ready(function(){ 
    $("input").blur(function(){ 
     alert("The input type is:" + $(this).attr("type")); 
    }) 
}); 
0

這應該工作...

$(document).ready(function(){ 
    $("input").blur(function(){ 
     var type = this.type; 
     alert("The input type is:" + type); 
    }) 
}); 
+0

爲什麼downvote? – Ryan

+1

+1當然這個工作,並且不浪費時間再次包裝這個$ –

0

爲什麼不經歷,看看有什麼屬性/屬性將是最有用的?

$(document).ready(function(){ 
    $("input").blur(function(){ 
     for (var x in this) 
      alert(x + ":" + this[x]); 
    }) 
}); 
5

我怎樣才能deteminedetermine這是否是一個輸入,選擇,文本等?

注意selecttextarea, 「等」 的元素並不受$('input')。你可能寧願使用$(':input')來獲得全部。

$(document).ready(function(){ 
    $(':input').blur(function(){ 
     alert('The tag is:' + this.tagName); 
     if (this.tagName == 'INPUT') { 
      alert("The input type is:" + $(this).attr('type')); 
     } 
    }) 
}); 
相關問題