javascript - Bootstrap 阻止表单提交

标签 javascript php jquery forms twitter-bootstrap

我正在使用 startbootstrap-clean-blog-1.0.2模板作为我的一般项目的基础。我目前正在制作一个小列表/ View 应用程序(我第一次尝试这样的事情)。当我单击表单中的“提交按钮”时,联系表单的 bootstaps 验证脚本运行并阻止表单由于“​​indexof”冲突/错误而提交(如果我猜对的话)

使用 Chromes 开发者工具,当我点击提交按钮时,我发现了以下错误:

Uncaught TypeError: Cannot read property 'indexOf' of undefined 
(Clean-blog.js:25)

$.jqBootstrapValidation.submitSuccess 
(Clean-blog.js:25)

(anonymous function)
Clean-blog.js:25

jquery.js:4409 jQuery.event.dispatch
(jquery.js:4095) 

jQuery.event.add.elemData.handle
(jquery.js:4095)

我对 javascript 或 jQuery 没有真正的了解,仍在学习 PHP。这些错误似乎与联系表单的验证脚本有关,而我的列表/查看页面与之无关(或者我认为)。我要做的就是确保我的表单有效(当我单击按钮时,它会转到 submitted.php 页面)。我怎样才能让页面提交?

我看过很多帖子询问“如何防止提交”,但没有关于如何在 Bootstrap 中获取表单以在堆栈上提交的问题。

这是我的代码:

<form class='' action='sent.php' method='post' name='sendTest'>
                    <ul>
                        <li>
                            <h2>TEST</h2>
                        </li>
                        <li>
                            <label for='name'>Name:</label>
                            <input type='text' name='name' />
                        </li>
                        <li>
                            <button type='submit'>Insert Name</button>
                        </li>
                    </ul>

                </form>

最佳答案

clean-blog需要一个 ID 为 name(var name = $("input#name").val()) 的输入元素,它在您的代码中不存在

<input type='text' name='name' id="name"/>

关于javascript - Bootstrap 阻止表单提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29113180/

相关文章:

javascript - 仅将 CSS 规则应用于 <tr> 中的第一个 <td> 而不分配类/id?

javascript - 需要在 Antd Datepicker 中编辑 Moment 以显示月份的全名

java - Zend Server CE 和 BIRT 与 Javabridge 集成

php - MySQL,如何插入空日期

php - 确定现有字符串的所有子字符串的最快方法

php - CakePHP - 使用 php 变量加载 View 并在 ajax 中返回

javascript - 避免点击触发焦点偏离

javascript - 如何让 webglcontextrestored 被解雇

Javascript 使文本变为粗体?

javascript - 将整个数组的内容推送到多维数组的一个索引中