javascript - 提交按钮在模态弹出窗口中不起作用,但单击按钮有效

标签 javascript html css form-submit addeventlistener

我有一个带有模态包装器类的 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 函数取消了提交表单的点击。

关于javascript - 提交按钮在模态弹出窗口中不起作用,但单击按钮有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59647195/

相关文章:

javascript - body.style.backgroundColor 和 window.getComputedStyle(body).getPropertyValue ('background-color' 的区别)

html - 如何在 PrimeNG 中单击后使焦点或边框消失

css - 使用一个类而不是几个

javascript - 点击谷歌地图移动标记

javascript - 阻止 IE 用户加载网页

javascript - 使用js插件修改typescript中的Event

html - 206 - 加载 mp3 文件时的部分内容状态

c# - 从 ajax 数据创建的下拉列表中绑定(bind)数据

CSS:如何定位表格内的特定单元格?

javascript - 如何禁用导航覆盖中的主体滚动并在主体中启用它?