保定网站建设,网站推广,网站优化服务,保定专业的PHP网站制作机构!

JavaScript动态选择单选框Radio代码 click()方法

发表于:2009年04月02日 03时  作者:dx_andy

一不小心忘记了怎样使用JavaScript动态选择单选框了,试了很多方法:focus(),select()…都无济于事。最后终于用click()方法搞定。记录在此,以后忘了方便查看。

HTML代码如下

<input type=”radio” name=”data[Store][type]” class=”radio” id=”storeType1″ value=”1″ /><label for=”storeType1″>全部</label>
<input type=”radio” name=”data[Store][type]” class=”radio” id=”storeType2″ value=”2″ /><label for=”storeType2″>女装</label>
<input type=”radio” name=”data[Store][type]” class=”radio” id=”storeType3″ value=”3″ /><label for=”storeType3″>男装</label>

JavaScript用的jQuery框架

JavaScript代码如下

jQuery(function() {
jQuery(‘.radio[name*=Store][name*=type][value=1]‘).click();
});

 订阅“PHPLAMP博客”方便及时获取网站内容

PHPLAMP博客是专注于网站建设,搜索引擎研究,网站推广,网站优化的IT博客。

发表一下您对本文的意见