-4

在我的 HTML 中使用现有 JavaScript 时遇到了挑战。我的 HTML 是两个单选按钮和元素“textarea”。When one radiobutton is selected (button: No) the textarea has to be shown and when the other (button: Yes) is selected it has to be hidden.

<span><input type="radio" name="feedback" id="Yes" value="Yes"><label for="Yes">Yes</label></span>
<span><input type="radio" name="feedback" id="No" value="No"><label for="No">No</label></span>

<div class="">
  <h5>lorem ipsum da lore</h5>
  <textarea>Lorem ipsum da lore</textarea>
</div>

我必须使用以下 JavaScript 来实现预期的效果。我对 JavaScript 还很陌生,所以我希望有人能解释下 JavaScript 代码的最佳方法是什么:

    $("input.kpn-bh-hideShow").change(function(){
    var id1 = $(this).attr('class').split(' ')[1];
    var id2 = $(this).attr('class').split(' ')[2];

    if(id1 && id2){
        $('#' + id1)
            .hide()
            .find('input, select')
            .attr("disabled","disabled");

        $('#' + id2)
            .show()
            .find('input, select')
            .filter(":visible")
            .removeAttr("disabled");
    }else{
        $('#' + id1)
            .hide()
            .find('input, select')
            .attr("disabled","disabled");
    }
4

1 回答 1

1
    **check out this code for this ** 
    <form name="f">
     <input type="radio" id="a" name="a"/>
     <input type="radio" id="b" name="a" />
     <textarea>here is a textarea</textarea>

    </form>
<script type="text/javascript">
//A link for the jquery library must be added here
$("#a").onclick(function (){
$("textarea").css("display","none");

});
$("#b").onclick(function (){
$("textarea").css("display","block");
});
</script>
于 2013-01-16T21:22:27.803 回答