开发者

Easiest/cleanest way to get the value of the current <input> element

I want to get the value of the current <input type="radio"> element 开发者_开发百科in its onClick.

I need something like:

<input type="radio" name="myRadio" value="something" onClick="theValueOfThisInput">

I can't use getElementById() because all my radio buttons have the same id.

I've currently done it by wrapping all the inputs in a <div> and getting the elements of the <div> by index, but I won't even bother posting it because I don't think it would be helpful to anyone.

Can someone recommend a good way to do this ?

Thanks,


Have you tried

this.value;

?


this.value should certainly work.

Try:

<input type="radio"
        name="myRadio"
        value="something"
        onclick="alert(this.value)" />

And the 'alert' function can be replaced with whatever function call you wish.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜