[英]I have 2 text Boxes and one button! When I click on button it should write 1 in the chosen text box but my code is not working
[英]when i click the open button a text box should appear in the page
當我單擊活動按鈕時,頁面中應出現一個框,當我單擊關閉時,它應從頁面中隱藏
<div class="btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-secondary ">
<input type="radio" name="options" id="option1" autocomplete="off" checked> Open
</label>
<label class="btn btn-secondary">
<input type="radio" name="options" id="option2" autocomplete="off"> Closed
</label>
</div>
使用單選按鈕的更改事件
$("input[name='options']").on('change',function(){ if($(this).attr('id') == 'option1'){ $('#myDiv').show(); }else{ $('#myDiv').hide(); } })
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div style="height:100px" id="myDiv">MY DIV WILL BE HERE</div> <body> <div class="btn-group btn-group-toggle" data-toggle="buttons"> <label class="btn btn-secondary "> <input type="radio" name="options" id="option1" autocomplete="off" checked> Open </label> <label class="btn btn-secondary"> <input type="radio" name="options" id="option2" autocomplete="off"> Closed </label> </div>
您可以使用引導模式和模式按鈕在單擊按鈕時打開一個框。 如果你想制作一個自定義按鈕,那么這里是 jquery 的代碼。
$(document).ready(function()
{
$("button.active").on("click",function()
{
$(".page-box").toggle();
//page-box is the box container which you want to open
})
});
那是你要的嗎 ?
$(document).ready(function() { $('input[name=options]').change(function(e) { var isOpen = $(this).val() == "Open"; $('#box').toggle(isOpen); }); });
#box { padding-top: 15px; }
<div class="btn-group btn-group-toggle" data-toggle="buttons"> <label class="btn btn-secondary "> <input type="radio" name="options" value="Open" id="option1" autocomplete="off" checked> Open </label> <label class="btn btn-secondary"> <input type="radio" name="options" value="Closed" id="option2" autocomplete="off"> Closed </label> </div> <div id="box">More Info</div> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.