使用多组单选按钮,如何取消隐藏和隐藏图像
using multiple sets of radio buttons, how can I unhide and hide images
图像//使用按钮隐藏和显示图像
根据单选按钮/复选框选择的显示图像
<img id="storage_drawer" src="images/placeholder/get_hardware/storage_drawer.png" />
<img id="cash_drawer" src="images/placeholder/get_hardware/cash_drawer.png" />
形成两组单选按钮//通过javascript函数更改为复选框
<input type="checkbox" id="cashdrawer" name="type" value="cashDrawer" class="unique" >
<input type="checkbox" id="cashStorage" name="type" value="storageDrawer" class="unique">
//second set of radio buttons
<input type="checkbox" id="single" name="type2" value="singleLine" class="unique" >
<input type="checkbox" id="multi" name="type2" value="multiLine" class="unique" >
</form>
脚本的开始
$(document).ready(function(){
to make make checkboxes have the functionality of radio buttons
var $inputs = $(".unique");
$inputs.change(function(){
$inputs.not(this).prop('checked');
});
return false;
radio buttons -- first set of radio buttons
$("input[name$=type]").click(function(){
var value = $(this).val();
//Cash Drawers
if(value == 'cashDrawer') {
$("#cash_drawer").show();
$("#storage_drawer").hide();
}
else if( value == 'storageDrawer') {
$("#storage_drawer").show();
$("#cash_drawer").hide();
}
})
$("#cash_drawer").hide();
$("#storage_drawer").hide();
second set of radio buttons
$("input[name$=type2]").click(function(){
var value = $(this).val();
//Barcode Scanners
if(value = 'singleLine') {
$("#sinlgeBarcode").show();
$("#multiBarcode").hide();
}
else if(value == 'multiLine') {
$("#multiBarcode").show();
$("#sinlgeBarcode").hide();
}
})
$("#sinlgeBarcode").hide();
$("#multiBarcode").hide();
});
});
脚本结束
如果您的单选框具有相同的名称属性,它们将表现为单选按钮,即组中只能有一个选项处于活动状态,但如果每个按钮都有自己的名称,它们都可以被选中。
因此,如果你有一个这样的无线电集合:
<form>
<input type="radio" name="1">
<input type="radio" name="2">
<input type="radio" name="3">
</form>
你可以用一个小javascript让它们表现得像复选框:
// This will allow the radio boxes to toggle on of.
$("input[type=radio]").click(function(){
$(this).attr("checked", !$(this).attr("checked"));
});
编辑:
我用一个工作例子做了一个js小提琴手,也许它会给出一些答案。
http://jsfiddle.net/uPp82/1/
相关文章:
- 根据单元格内容隐藏/取消隐藏行
- 我如何才能获得隐藏/取消隐藏按钮来同时发送帖子请求
- 在其他元素的基础上隐藏/取消隐藏jsp元素
- 如何隐藏/取消隐藏窗体
- 聚合物 IronRessizeableBehavior 当“可调整大小”元素被隐藏/取消隐藏时,不会触发 Iron 调整
- 使用挖空.js隐藏/取消隐藏时不应用 jquery UI 主题
- 无法隐藏/取消隐藏表单内的按钮
- 在给定行索引和表 ID 的情况下隐藏/取消隐藏表行
- 使用 jQuery 隐藏取消隐藏列
- JS使用CSS格式隐藏/取消隐藏
- 关于django模板中表单字段值的动态隐藏/取消隐藏选项卡
- 如何隐藏/取消隐藏代码镜像
- 带有隐藏/取消隐藏选项的Javascript图像滑块
- 使用Javascript隐藏/取消隐藏带有文本输入的表行,具体取决于所选的下拉选项
- 隐藏/取消隐藏带有密码的菜单链接
- 通过悬停来隐藏/取消隐藏HTML部分
- 隐藏/取消隐藏面板的JavaScript函数
- 移动(不是滚动)锚点使用javascript,在函数中的元素被隐藏/取消隐藏
- 如果单击按钮,则使用Jquery隐藏/取消隐藏文本框
- 使用 Jquery 或 Javascript 隐藏/取消隐藏 html 元素