How do you test whether a field is of type "select" in jQuery
How do you test an input field for typ开发者_运维技巧e "select", e.g. for a radio button, it's
if($('#' + field).attr('type') == 'radio'{
....
}
What do you write for a select box?
You can use .is()
and an element selector, like this:
if($('#' + field).is('select')) {
Or check .length
of an #id
selector only for that element type like this (a bit slower):
if($('select#' + field).length) {
Or nodeName
(or tagName
) like this:
if($('#' + field)[0].tagName == 'SELECT') {
Or without jQuery at all (fastest):
if(document.getElementById(field).tagName == 'SELECT') {
精彩评论