简体   繁体   English

使用jquery / javascript选择框将验证复选框

[英]using jquery/javascript select box will validate the checkbox

I am getting stuck in a page,where I'm using selectbox & checkbox,and they will behave like - in the select box options are ABC,BCD,BDE,AD,BE & in the checkbox the option are A,B,C,D,E.When I am selecting (suppose) BDE(or AD) from select box....in the checkbox B,D,E(or A and D) will be checked(automatic). 我陷入了一个页面,我正在使用选择框和复选框,它们会表现得像 - 在选择框中选项是ABC,BCD,BDE,AD,BE&复选框中的选项是A,B,C ,D,E。当我从选择框中选择(假设)BDE(或AD)....在复选框B中,将检查D,E(或A和D)(自动)。

Any idea...or input will be appreciated. 任何想法......或输入将不胜感激。

my code(given below): 我的代码(如下):

Edited: one more thing is that if I am using selectbox like(mention below),and want to implemented checked checkbox according to the select box.Any clue... 编辑:还有一件事是,如果我使用selectbox(如下所述),并希望根据选择框实现选中复选框。任何线索......

<body>
<form>
<select name="item" id="item" class="item" onChange=list(this.value) >
<script type="text/javascript">
document.write("<option value=-1>Item</option>");
count=item.length;
for(i=0;i<count;i++)
document.write("<option value="+i+">"+item[i]+"</option>");
</script>
</select>
<table>
<td>
<input type="checkbox" name="A" id="A" value="A" >A<br>
<input type="checkbox" name="B" id="B" value="B">B<br>
<input type="checkbox" name="C" id="C" value="C">C<br>
<input type="checkbox" name="D" id="D" value="D">D<br>
<input type="checkbox" name="E" id="E" value="E">E<br>  
</td>
</table>
</form>
</body>

and on changing that particular select items(item) can all those option can be written in jquery(instead what you have answered) what u have mention(@ mohon ram) 并且在更改特定的选择项目(项目)时,所有这些选项都可以用jquery编写(而不是你已经回答的)你所提到的(@ mohon ram)

and I have got a link here but not able to sort it on my answer perspective. 在这里有一个链接但无法根据我的答案视角对其进行排序。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="http://code.jquery.com/jquery-1.7.2.js"></script>
<script language="javascript">
$(document).ready(function(){

$("select#select_element").change(function(){
    var select_val = $.trim( $("select#select_element option:selected").attr("test") );
    var select_val_arr = select_val.split(",");
    $("input.checkbox").prop("checked",false);
    $.each(select_val_arr, function(i,val){
        $("input:checkbox#"+val).prop("checked",true);
    });
});
$("select#select_element").trigger("change");
});
</script>

</head>
<body>
<select id="select_element">
    <option test="A,B,C" value="ABC">ABC</option>
    <option test="B,C,D" value="BCD">BCD</option>
    <option test="B,D,E" value="BDE">BDE</option>
    <option test="A,D" value="AD">AD</option>
    <option test="B,E" value="BE">BE</option>
</select>

<input type="checkbox" id="A" value="A" class="checkbox" />A
<input type="checkbox" id="B" value="B" class="checkbox"  />B
<input type="checkbox" id="C" value="C" class="checkbox"  />C
<input type="checkbox" id="D" value="D" class="checkbox"  />D
<input type="checkbox" id="E" value="E" class="checkbox"  />E
<input type="checkbox" id="F" value="F" class="checkbox" />F
</body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM