【发布时间】:2011-10-20 02:35:50
【问题描述】:
是否有一段 Javascript 可以阻止表单提交按钮执行功能
我正在使用使用 MVC 模式的 CodeIgniter 框架。
因此,当您单击按钮时,它会调用控制器函数,然后再调用模型函数等。
我尝试在 Javascript 中使用各种东西,包括返回、历史返回。有什么可以阻止任何事件的发生吗?
这是我的代码:
function confirmation() {
var answer = confirm("Delete Record?")
if (answer)
{
}
else
{ //reloads current page - however it still continues to function
window.redirect("http://localhost/midas/index.php/control_panel/user_records");
}
}
如果我说“取消”,它仍然会继续执行该功能。有什么办法可以停止浏览器?
这是我的 php 代码:
//js = is a variable which stores the javascript code
echo form_submit('view','View', $js);
这会像这样创建 html 输出:
<input type="submit" onclick="confirmation()" value="View" name="view">
【问题讨论】:
标签: php javascript codeigniter