开发者

marking a radio input as slected when page is loaded

开发者 https://www.devze.com 2023-02-22 21:57 出处:网络
I have two radio buttons. I want one of them to be shown as selected when the page loads. Which property I should use, and how?

I have two radio buttons. I want one of them to be shown as selected when the page loads. Which property I should use, and how?

Example:

<input type="radio" name="musictype2" value="rock" de开发者_开发知识库fault> Rock<br>
<input type="radio" name="musictype2" value="alternative"> Alternative<br>


<input type="radio" name="test" value="2" checked="checked" />test

like this?


<input type="radio" name="genreselect" value="rock" checked="checked" />
<input type="radio" name="genreselect" value="alternative" />

In this case "rock" is preselected.


<form>
    <input type="radio" name="genre" value="rock" checked /> Rock<br />
    <input type="radio" name="genre" value="alternative" /> Alternative
</form>

This is the correct way. The name attribute needs to be the same in order for them to switch between.

Check it here.


This is how you use the checked attribute:

<input type=radio name="my_name" VALUE="my_value" checked />
0

精彩评论

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