开发者

getting a class of two class with attr in input, how is it?

i have two class, i want getting with attr first class in input. how 开发者_如何学JAVAis it?

classes:

1.autocomplete

2.date

<input class="autocomplete date">
$('input').attr(class) 
//output 'autocomplete date' i want output this: 'autocomplete '

With respect.


Split the string on whitespace and select the first element of the result:

$("input").attr("class").split(" ")[0]


Use the following:

$('input').attr(class).split(' ')[0]

The split method will return an array of all classes, and you can use [0] to get the first element in that array.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜