如果可见,则使文本框成为必填项(基于单选按钮选择是/否,文本框可见)

问题描述:

我有单选按钮列表,选择是/否,我需要隐藏/显示文本框。

如果选择是,则文本框可见,如果否则隐藏。

如果文本框可见,那么我需要使用Jquery强制使用。



我尝试过:



如果检查了radiobtn.selected

则必须使用textbox。

I have radio button list and on selection of Yes/No ,I need to hide/show textbox.
If yes is selected, then textbox is visible and If No then hidden.
If textbox is visible then I need to make it mandatory using Jquery.

What I have tried:

If radiobtn.selected checked
Then textbox is mandatory.

试试这个



try this

<html>
<head>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

    <script>
        function check() {
            var value =


('input [name = opt]:checked')。val();
if(value =='Yes')
('input[name=opt]:checked').val(); if (value == 'Yes')


('#txtbox')。show();
else
('#txtbox').show(); else