从多个选项中仅选择了一个值选项 [英] Selected just only one value option from several option

查看:105
本文介绍了从多个选项中仅选择了一个值选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<pre>
<td>
    <select name="proses1" class="form-control">
    <option value="0" selected>-------</option>
    <option value="1">1-Itemset</option>
    <option value="2">2-Itemset</option>
    <option value="3">3-Itemset</option>
    </select>
</td>
<td>
<select name="proses2" class="form-control">
    <option value="0" selected>-------</option>
    <option value="1">1-Itemset</option>
    <option value="2">2-Itemset</option>
    <option value="3">3-Itemset</option>
</select>
</td>
<td>
<select name="proses3" class="form-control">
    <option value="0" selected>-------</option>
    <option value="1">1-Itemset</option>
    <option value="2">2-Itemset</option>
    <option value="3">3-Itemset</option>
</select>
</td>
</pre>   

我像上面一样具有html标签..例如,我想从proses1中选择1-itemset,然后从proses2中选择1-itemset,
来自proses1的1个项目集,它返回到默认值(-------), 所以重点是我想要选项只能选择一个选项..我如何做到这一点.在此之前感谢

i have tag html like above.. and i want for example i selected 1-itemset from proses1 and then i choose 1-itemset from proses2,
1-itemset from proses1 it get back to default(-------), so the point is i want option just can selected one option.. how i can make it. thanks before

推荐答案

尽管您还没有说过想要哪种类型的过程,但我还是建议您使用jQuery

Although you havent said what type of process you want, i suggest you do it with jquery like

var selects = $("select[name=proses1],select[name=proses2],select[name=proses3]");
selects.on("change",function(evt){
  selects.not("[name=" + evt.target.name + "]").val(0);
});

FIDDLE

编辑

要使用此功能,首先需要在代码中添加jQuery库,然后将其放入$(document).ready()方法中.作为摘要,请将代码放在头部以下下方.

To use this, first you need to add jQuery library to your code then place this inside $(document).ready() method. As a summary, place the code below inside your head section.

<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  var selects = $("select[name=proses1],select[name=proses2],select[name=proses3]");
  selects.on("change",function(evt){
    selects.not("[name=" + evt.target.name + "]").val(0);
  });
});
</script>

这是在select元素中添加具有.on("change")方法的onChange事件处理程序,并且在该处理程序中,所有select元素值都设置为0,这是第一个,但当前版本除外.

What this does is to add an onChange event handler with .on("change") method to the select elements and in that handler all select elements values are being set to 0 which is the very first option except the current one.

这篇关于从多个选项中仅选择了一个值选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆