點擊文字選中radio

<html>
<body>
<form action="" name="form1" method="post">html


<br />
<label style="cursor:pointer" for="man">
<input type="radio" value="http://fanjf.iteye.com/blog/男" name="man" id="man"/>男
</label>
<label style="cursor:pointer" for="man2">
<input type="radio" value="http://fanjf.iteye.com/blog/女" name="man" id="man2"/>女
</label>
</form>post

<input type="radio" id="male" name="sex" checked="checked"/><label style="cursor:pointer" for="male">男1</label> this

<input type="radio" id="female" name="sex" /><label style="cursor:pointer" for="female">女1</label> spa

</body>
</html>orm

 

 

有ID的能夠用以上方法,若是沒有id呢,那隻能本身寫js了,一下方法僅供參考htm

 

$(".isplist").click(function(){
//alert($(this).val());
$(this).find("input[type=radio]").attr("checked", 'checked');
});blog

 

<div name="isp" class="isplist"><input type="radio" name="ispname" value="1"> 聯通 </div>
<div name="isp" class="isplist"><input type="radio" name="ispname" value="2"> 電信 </div>
<div name="isp" class="isplist"><input type="radio" name="ispname" value="3"> 移動 </div>
<div name="isp" class="isplist"><input type="radio" name="ispname" value="4"> 鐵通 </div>
<div name="isp" class="isplist"><input type="radio" name="ispname" value="5"> 長城 </div>
<div name="isp" class="isplist"><input type="radio" name="ispname" value="6"> 廣電 </div>
<div name="isp" class="isplist"><input type="radio" name="ispname" value="7"> 教育網 </div>
<div name="isp" class="isplist"><input type="radio" name="ispname" value="8"> 其它 </div>get

 

 window.onload = function () {
//點擊radio後面的文本選中radio
//    labels = document.getElementById('scalul').getElementsByTagName('span');
//    for (i = 0, j = labels.length; i < j; i++) {
//        labels[i].onclick = function () {
//            var vastr = $(this).parents("li").find("input").val();
//            $(this).parents("li").find("input[type=radio][value=" + vastr + "]").attr("checked", 'checked');
//        }
//    }
//點擊整個li選中其裏面的radio
    labelsa = $(".scalul .li").find("li");
    for (i = 0, j = labelsa.length; i < j; i++) {
        labelsa[i].onclick = function () {
           var vastra = $(this).find("input").val();
            $(this).parents("li").find("input[type=radio][value=" + vastra + "]").attr("checked", 'checked');
        }
    }

}input

相關文章
相關標籤/搜索