Html 单击模板上的单选按钮
你好,我需要知道我如何给一个单选按钮点击功能。我需要一个特定类型的文本框出现时,我点击单选按钮。我尝试了很多代码,但没有任何效果 单选按钮代码为:Html 单击模板上的单选按钮,html,Html,你好,我需要知道我如何给一个单选按钮点击功能。我需要一个特定类型的文本框出现时,我点击单选按钮。我尝试了很多代码,但没有任何效果 单选按钮代码为: <html> <p>Choose your strategy:</p> <form action="" method="post"> <input type="radio" name="choice-strategy" id="choice-strategy
<html>
<p>Choose your strategy:</p>
<form action="" method="post">
<input type="radio" name="choice-strategy" id="choice-strategy-long" checked>
<label for="choice-strategy-long">Long</label>
<div class="reveal-if-active">
<label for="which-inputs">Good call. What's the name of your favorite dog?</label>
<input type="text" id="which-inputs" name="which-inputs" class="require-if-active" data-require-pair="#choice-strategy-long">
</div>
<input type="radio" name="choice-strategy" id="choice-strategy-short">
<label for="choice-strategy-short">Short</label>
<div class="reveal-if-active">
<input type="radio" name="choice-strategy" id="choice-strategy-longshort">
<label for="choice-strategy-longshort">Long and Short</label>
<div class="reveal-if-active">
</form>
</html>
选择您的策略:
长的
好电话。你最喜欢的狗叫什么名字?
短
长短
您可以试试这个
<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
<p>Choose your strategy:</p>
<form action="" method="post" id="formid">
<div>
<input type="radio" name="choice-strategy" id="long" checked>
<label for="choice-strategy-long">Long</label>
<div class="long each_text">
<label for="which-inputs">Good call. What's the name of your favorite dog?</label>
<input type="text" id="which-inputs" name="long" class="require-if-active" data-require-pair="#choice-strategy-long">
</div>
</div>
<div>
<input type="radio" name="choice-strategy" id="short">
<label for="choice-strategy-short">Short</label>
<div class="hidden short each_text">
<label for="which-inputs">Short</label>
<input type="text" id="which-inputs" name="short" class="require-if-active " data-require-pair="#choice-strategy-long">
</div>
</div>
<div>
<input type="radio" name="choice-strategy" id="longshort">
<label for="choice-strategy-longshort">Long and Short</label>
<div class="hidden longshort each_text">
<label for="which-inputs">Long and Short?</label>
<input type="text" id="which-inputs" name="longshort" class="require-if-active" data-require-pair="#choice-strategy-long">
</div>
</div>
</form>
<script type="text/javascript">
$('#formid input[type="radio"]').click(function(){
$('.each_text').addClass('hidden');
$('.each_text input').val('');
var tovisible = $(this).attr('id');
$('.'+tovisible).removeClass('hidden');
});
</script>
<style type="text/css">
.hidden{
display: none;
}
</style>
</html>
选择您的策略:
长的
好电话。你最喜欢的狗叫什么名字?
短
短
长短
长短?
$('#formid input[type=“radio”]')。单击(函数(){
$('.each_text').addClass('hidden');
$('.each_text input').val('');
var tovisible=$(this.attr('id');
$('.+tovisible).removeClass('hidden');
});
.隐藏{
显示:无;
}
单击每个单选按钮时是否要显示另一个文本框?是,如果单击Short,这就是我想要的。然后在它下面的一个文本框中隐藏旧的是吗?是的,没错!!!!非常感谢。如果是一张桌子呢?我将在交易日向您展示与表格股票选择标准相关的代码。Price(min,max){{form.Price_1_min.errors}{{form.Price_1_min}}{{form.Price_1_max.errors}{{form.Price_1_max}我的意思是,如果它是一种带有表的字段集,请使用相同的想法。