我需要在选择单选按钮时显示一个下拉框

i need to display a drop down box on selection of a radio button

本文关键字:一个 显示 选择 单选按钮      更新时间:2023-12-21

在选择特定的单选按钮时,我需要显示一个下拉框,并为另一个按钮隐藏它!有人能帮我用jquery/javascript编写代码吗??

假设您的HTML是这样的:

<p class="help">Selection:</p>
    <div id='buttons'>
        <label><input type="radio" name="select" id="option1" /> Option 1 </label>
        <label><input type="radio" name="select" id="option2" /> Option 2</label>
        <label><input type="radio" name="select" id="option3" /> Option 3</label>
    </div>
    <div id="list">
        <label>Please Select From the List: 
            <select id="mySelect">
                <option>True</option>
                <option>False</option>
            </select>
        </label>
    </div>​
</p>

然后你可以这样写一些Jquery

$(document).ready(
    function()
    {
        $("#option1, #option2, #option3").click(
            function()
            {
                if (this.id == "option3")
                    $("#mySelect").hide();
                else
                    $("#mySelect").show();
            });
    });​

工作示例:http://jsfiddle.net/AVFuY/3/

function show(){
  var element = document.getElementById('numbers');
  element.style.display = 'inline';
}
function hide(){
  var element = document.getElementById('numbers');
  element.style.display = 'none';
}
<button onclick="show();">Show</button>
<button onclick="hide();">Hide</button>
<select id="numbers">
  <option>1</option>
  <option>2</option>
  <option>3</option>  
</select>