开发者

How do you test whether a field is of type "select" in jQuery

开发者 https://www.devze.com 2023-01-20 09:37 出处:网络
How do you test an input field for typ开发者_运维技巧e \"select\", e.g. for a radio button, it\'s

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') {
0

精彩评论

暂无评论...
验证码 换一张
取 消