[英]A submit button not working in modal pop but a click button is working
我有一个带有模态包装器类的 div,它在页面上创建一个叠加层。
div 有一个弹出模态,它打开一个带有模态反馈 id 的 HTML 表单。 模态使用 CSS 定位在页面的中心。 表单有一个提交按钮,id 为提交,我在提交时使用事件侦听器进行监听。 这个提交按钮不起作用。
当我从模态包装器中删除此表单时,它工作正常。 是什么阻止提交按钮提交? 谁能指导我如何解决这个问题?
我尝试搜索与此问题相关的许多答案,但似乎没有一个与我的问题相关或与我的问题相关。
这是我的 html 标记。
<div id="modal_wrapper" class="modal_wrapper">
<div id="modal_window">
<div style="text-align: right;"><a id="modal_close" href="#">close <b>X</b></a></div>
<p class="better-exp-p" id="better-exp-p">Select House Type:</p>
<form id="modal_feedback" method="POST" action="<?php echo url_for('/landing_page.php') ;?>">
<span class="buy-let-furnished">
<label for="buy" class="buy-let-furnished-label">Buy</label>
<input class="selector" id="buy" name="buy-let-furnished" type="radio" value="1">
<label for="let" class="buy-let-furnished-label">Let</label>
<input class="selector" id="let" name="buy-let-furnished" type="radio" value="2">
<label for="let" class="buy-let-furnished-label">Fully Furnished</label>
<input class="selector" id="furnished" name="buy-let-furnished" type="radio" value="3">
</span>
<span class="Bedrooms">
<p>Number of Bedrooms :</p>
<label for="onebedrooms" class="bedrooms-label">1</label>
<input class="selector" id="onebedrooms" name="bedrooms" type="radio" value="1">
<label for="twobedrooms" class="bedrooms-label">2</label>
<input class="selector" id="twobedrooms" name="bedrooms" type="radio" value="2">
<label for="threebedrooms" class="bedrooms-label">3</label>
<input class="selector" id="threebedrooms" name="bedrooms" type="radio" value="3">
<label for="morethanthreebedrooms" class="bedrooms-label">more than 3 </label>
<input class="selector" id="morethanthreebedrooms" name="bedrooms" type="radio"
value="4">
</span>
<span class="location">
<label for="area" class="area-head">Location </label>
<input class="selector" id="location" name="location" type="text" value="">
</span>
<button type="submit" class="better-exp-p submit" id="submit" name="feedbackForm"
value="submit">Search</button>
<button id="expand" type="expand" name="feedback-expand-Form" value="More-search">More Detailed
Search</button>
</form>
</div> <!-- #modal_window -->
</div> <!-- #modal_wrapper -->
<!----js file --->
document.getElementById('modal_feedback').addEventListener('submit', validate);
validate(e){
e.preventDefault();
console.log('was clicked')
console.log(this);
}
当我单击按钮时,表单没有响应
我注意到 clickHandler 函数取消了提交表单的点击。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.