我正在使用 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/