开发者

Get value for Textbox with separator

开发者 https://www.devze.com 2023-01-15 16:23 出处:网络
I\'d like get a string with the value from some Textbox (with a specific class) and the values should be separate by a comma.

I'd like get a string with the value from some Textbox (with a specific class) and the values should be separate by a comma.

Any idea ?

Thanks,

Update1 :

I have this

   <input type="text" id="A" class="test" value="aa">
   <input type="text" id="B" class="test" value="bb"&g开发者_JAVA技巧t;

I'd like this : aa,bb


get the value then use split.

var str = 's,s,e,a,t,f';
var str2 = str.split(",");
alert(str2[2])​;​ // alerts e

you can do var str = $('#someTextbox').val() then proceed as above.

that is if I understood you clearly.


In your update, you can do it this way,

var str = $('.test').map(function(){
    return this.value;
}).get().join(',');

str now holds all the values found separated by comma, here's a demo cause I'm not good at explaining... :)

0

精彩评论

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