开发者

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

开发者 https://www.devze.com 2023-03-21 04:28 出处:网络
i have two class, i want getting with attr first class in input. how 开发者_如何学JAVAis it? classes:

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

精彩评论

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