gpt4 book ai didi

javascript - 当我提交基于选择框的重定向页面时

转载 作者:行者123 更新时间:2023-11-28 11:44:39 25 4
gpt4 key购买 nike

我想在基于选项 url 提交后重定向页面,我尝试了以下代码,但它不起作用,下面的代码是否有任何问题。

请帮我解决这个问题。

<div class="row">

<div class="wow fadeInLeft animated col-sm-12 col-md-12" data-wow-delay=".2s" data-wow-duration="1500ms">
<div class="san" style="padding:0px; ">

<div class="header-title">
<h3 style="text-align:center;"><strong>Donate Now </strong></h3>

<div class="hr hr-black"></div>
</div>
<br/>
<form id="comment-form1" name="contact-form1" onsubmit="return mysubmit();">
<input type="text" name="name" placeholder="Your Name.." required>
<input type="text" name="email" placeholder="Your Email.."required>
<input type="text" name="phone" placeholder="Your 10 digit Phone.."require pattern="[0-9]{10}">

<select id="option" class="chosen" style="width:500px;">
<option selected disabled>Select Bank</option>
<option value="netbanking.hdfcbank.com/netbanking/?_ga=2.196148587.673827790.1549438128-1636006557.1549438128">Hdfc Bank</option>
<option value="www.icicibank.com/safe-online-banking/safe-online-banking.page?itm=nli_hp_0_btn_ib_loginbtn" >ICICI Bank</option>
<option value="netbanking.canarabank.in/entry/ENULogin.jsp" >Canara Bank</option>
</select>
<input name="submit" type="submit" value="Submit" /><br>
</form>
<br/><br/>
</div>
</div>

<script>
function mysubmit(){
//you can return false; here to prevent the form being submitted
//useful if you want to validate the form

window.location.href='https://'+document.getElementById('option').value;
}
</script>

</div>
</div>
</section>

最佳答案

您可以使用 Event.preventDefault()

document.getElementById('comment-form1').addEventListener('submit',(e)=>{
e.preventDefault();
window.location = ('https://'+document.getElementById('option').value);
})
<div class="row">

<div class="wow fadeInLeft animated col-sm-12 col-md-12" data-wow-delay=".2s" data-wow-duration="1500ms">
<div class="san" style="padding:0px; ">

<div class="header-title">
<h3 style="text-align:center;"><strong>Donate Now </strong></h3>

<div class="hr hr-black"></div>
</div>
<br/>
<form id="comment-form1" name="contact-form1">
<input type="text" name="name" placeholder="Your Name.." required>
<input type="text" name="email" placeholder="Your Email.."required>
<input type="text" name="phone" placeholder="Your 10 digit Phone.."require pattern="[0-9]{10}">

<select id="option" class="chosen" style="width:500px;">
<option selected disabled>Select Bank</option>
<option value="netbanking.hdfcbank.com/netbanking/?_ga=2.196148587.673827790.1549438128-1636006557.1549438128">Hdfc Bank</option>
<option value="www.icicibank.com/safe-online-banking/safe-online-banking.page?itm=nli_hp_0_btn_ib_loginbtn" >ICICI Bank</option>
<option value="netbanking.canarabank.in/entry/ENULogin.jsp" >Canara Bank</option>
</select>
<input name="submit" type="submit" value="Submit"/><br>
</form>
<br/><br/>
</div>
</div>

关于javascript - 当我提交基于选择框的重定向页面时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54548939/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com