html如何设置radio单选按钮默认选中效果

从标题看这个问题够简单,事实也是如此,不过在群里还是看到有初学者来询问这个问题,下面就展示一段代码实例,如果实现多个单选按钮实现其中的一个默认选中效果。

代码实例如下:

01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 <!DOCTYPE html> < html > < head > < meta charset = " utf-8" > < meta name = "author" content = "" /> < title >蚂蚁部落</ title > </ head > < body > < input type = "radio" name = "antzone" /> < input type = "radio" name = "antzone" /> < input type = "radio" name = "antzone" checked/> < input type = "radio" name = "antzone" /> < input type = "radio" name = "antzone" /> </ body > </ html >
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 < html > < head > < meta charset = " utf-8" > < meta name = "author" content = "" /> < title >蚂蚁部落 < body > < input type = "radio" name = "antzone" /> < input type = "radio" name = "antzone" /> < input type = "radio" name = "antzone" checked/> < input type = "radio" name = "antzone" /> < input type = "radio" name = "antzone" />
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 < html > < head > < meta charset = " utf-8" > < meta name = "author" content = "" /> < title >蚂蚁部落 < body > < input type = "radio" name = "antzone" /> < input type = "radio" name = "antzone" /> < input type = "radio" name = "antzone" checked/> < input type = "radio" name = "antzone" /> < input type = "radio" name = "antzone" />
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 < html > < head > < meta charset = " utf-8" > < meta name = "author" content = "" /> < title >蚂蚁部落 < body > < input type = "radio" name = "antzone" /> < input type = "radio" name = "antzone" /> < input type = "radio" name = "antzone" checked/> < input type = "radio" name = "antzone" /> < input type = "radio" name = "antzone" />

只要给要默认选中的radio标签上添加checked即可实现。

从标题看这个问题够简单,事实也是如此,不过在群里还是看到有初学者来询问这个问题,下面就展示一段代码实例,如果实现多个单选按钮实现其中的一个默认选中效果。 代码实例如下: 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 < html > < head > < meta charset = " utf-8" > < meta name = "author" content = "" /> < title >蚂蚁部落 < body > < input type = "radio" name = "antzone" /> < input type = "radio" name = "antzone" /> < input type = "radio" name = "antzone" checked/> < input type = "radio" name = "antzone" /> < input type = "radio" name = "antzone" /> 只要给要默认选中的radio标签上添加checked即可实现。
经验分享 程序员 微信小程序 职场和发展