2011-08-19 64 views

回答

0

下一个命令会给你一个元素的类型与inputId的ID:

$("#inputId").attr('type'); 

然后,你可以简单地检查你想了解它的类型什么。

+0

感谢@nayish .. –

-1
$type = $("#idOfYourPassField").attr("type"); 

if($type==='password') 
//its a password 
+0

有更好的方法来达到这个目的,肯定使用jQuery – 321X

0

你可以只使用:密码选择,看看它是否返回任何

if($(':password').length) { 
    Do something if exists 
} 
0

你可以if.length

if($("#haspassword input[type='password']").length > 0)

演示检查:http://jsfiddle.net/xU3se/

以上示例使用#haspassword检查特定表单。如果length大于零,那么做点什么。

+0

感谢@ Soltris –

0

你试过:password伪类吗?

+0

不,但我现在用它..谢谢。 –

1

$(selector).is(":password")会给你true
$(selector).attr("type")会给你password

点此查看demo