斯蒂芬大帝
2022-06-16 16:44:23
我有一個表單,其結果(鏈接列表)顯示在表單正下方的表格中。但是,我想添加一個功能,如果選中該復選框,那么結果中的所有鏈接都應該在不同的選項卡上打開。下面是我的代碼:<div class="card" id="emulstatform"> <div class="card-header"> <div class="card-title"> <div style="font-size: 25px"Filter</div> </div> </div> <br> <div class="card-body"> <div class="row"> <div class="col-xs-6"> <label name="start_date" class="control-label" style="width:35%;padding-left:15px">Start date</label> <input type="date" id="start_date" style="color:black;width:100px" ></input> </div> <div class="col-xs-6"> <label name="end_date" class="control-label" style="width:35%">End Date(Default: Current Date)</label> <input style="color:black;width:100px" id="end_date" type="date"></input> </div> </div> <br> <div class="row"> <div class="col-xs-6"> <label name="fruit_name" class="control-label" style="width:35%; padding-left:15px">Select a fruit</label> <select class="js-example-placeholder-single1 js-example-basic-multiple form-control" id="fruit_name" placeholder="Select" style="width:210px" multiple="multiple"> </select> </div> <div class="col-xs-6"> <label name="fruit_test" class="control-label" style="width:35%">Select fruit_TEST</label> <select class="js-example-placeholder-single2 js-example-basic-multiple form-control" style="width:210px" id="fruit_test" multiple="multiple"> </select> </div> </div> <div class="row"> <div class="col-xs-6"> <label name="fruit_version" class="control-label" style="width:35%; padding-left:15px">Select fruit message</label> </select> </div> </div> </div>每個鏈接的 url 格式為fruitdata/?id=1000,其中 id 是為不同水果更改的唯一參數。如何實現在不同頁面上打開這些鏈接的功能?
1 回答

白衣染霜花
TA貢獻1796條經驗 獲得超10個贊
如果我正確理解了您的問題,您需要以下內容才能打開新標簽:
<button onclick="myFunc()">open google in new tab</button>
<script>
function myFunc() {
window.open("https://www.google.com");
}
</script>
要打開多個標簽,您可以使用此代碼,但如果最終用戶正在運行彈出窗口阻止軟件(如 Chrome 內置的軟件),則它可能會自動阻止其他窗口/標簽打開。
let urls = ["https://stackoverflow.com", "https://stackexchange.com/"];
for (var i = 0; i<2; i++){
window.open(urls[i]);
}
要了解您的復選框何時被選中,此代碼可以提供幫助:
$("input[type=checkbox]").on('change',function(){
if($("input[type=checkbox]").is(':checked'))
alert("checked");
else{
alert("unchecked");
}
}
我希望這段代碼對你有所幫助。
添加回答
舉報
0/150
提交
取消