Javascript Jquery代码,单击单选按钮选择一个选项
你好,我是Html/Javascript/query/css新手,大约半年了。 我没有什么问题。 现在我正在尝试做一个函数/代码来实现这一点:我有两个单选按钮。单击第一个单选按钮选择第一个选项,然后删除其他选项。单击第二个单选按钮时,打开其他选项,并删除将其自身专用于第一个单选按钮的第一个选项Javascript Jquery代码,单击单选按钮选择一个选项,javascript,jquery,javaquery,Javascript,Jquery,Javaquery,你好,我是Html/Javascript/query/css新手,大约半年了。 我没有什么问题。 现在我正在尝试做一个函数/代码来实现这一点:我有两个单选按钮。单击第一个单选按钮选择第一个选项,然后删除其他选项。单击第二个单选按钮时,打开其他选项,并删除将其自身专用于第一个单选按钮的第一个选项 <form enctype="multipart/form-data"> <fieldset> <legend>מפרט טכני של הס
<form enctype="multipart/form-data">
<fieldset>
<legend>מפרט טכני של הסמארטפון:</legend>
<label for="memory">זיכרון פנימי:</label>
<input id="less1" type="radio" value="less" name="memory" onclick="(myFun())" /> פחות מ 1GB
<input id="more1" type="radio" value="more" name="memory" onclick="(myFun1())" />מעל 1GB
<br />
<label for="extra">אפשרות להרחבת זיכרון:</label>
<br />
<select size="5" id="sel">
<option name="extra" value="no1" id="no">לא</option>
<option name="extra" value="yes8">כן,8GB</option>
<option name="extra" value="yes16">כן,16GB</option>
<option name="extra" value="yes32">כן,32GB</option>
<option name="extra" value="yes64">כן,64GB</option>
</select>
</fieldset>
</form>
我在这里检查了另一个主题,它对我有一点帮助这就是你想要的代码。我删除了select事件,因为使用鼠标选择文本时会触发该事件 最好隐藏/显示元素,而不是删除它们
function myFun() {
// 1. Find the first option and set as selected
$("#sel").find('option').first().prop("selected",true)
// 2. Find its not selected siblings and hide it
.siblings('option:not(:selected)').hide();
// 3. The first radio button is selected, so show the first option
$("#no").show();
}
function myFun1() {
// 1. Find the last option, set as selected and show it
$("#sel").find('option').last().prop("selected",true).show()
// 2. Find its siblings and show them
.siblings('option:not(:selected)').show();
// 3. Hide the first option
$("#no").hide();
}
我想知道你想做什么。因此,如果单击要设置为选中的第一个单选按钮,则单击第一个选项并隐藏其他选项;如果单击第二个单选按钮,则显示隐藏的选项并隐藏第一个选项。对吗?没错。这就是我想要的你能添加评论吗*text*//向我解释你添加的其余文本在做什么?我知道它的作用,但是解释会帮助我了解未来的情况很好谢谢你的朋友//编辑来了//我还有一个问题。如果我删除$sel.find'option'。last.propselected,true.show,那么它将显示选项,而不选择最后一个选项。但当我按下第一个单选按钮,然后切换到第二个单选按钮时,它只显示滚动条。为什么?我如何做到这一点,它将显示4个选项而不选择最后一个?我设法做到了我的意愿$sel.find'option'。show.sillides'option:not:selected'。show;我改成了这个
function myFun() {
// 1. Find the first option and set as selected
$("#sel").find('option').first().prop("selected",true)
// 2. Find its not selected siblings and hide it
.siblings('option:not(:selected)').hide();
// 3. The first radio button is selected, so show the first option
$("#no").show();
}
function myFun1() {
// 1. Find the last option, set as selected and show it
$("#sel").find('option').last().prop("selected",true).show()
// 2. Find its siblings and show them
.siblings('option:not(:selected)').show();
// 3. Hide the first option
$("#no").hide();
}