javascript event.preventdefault() 在 jquery.click with Rails
javascript event.preventdefault() not working on jquery.click with Rails
我有一个 Rails 表单。但我不想通过Rails提交表格。我想通过Ajax提交。
在视图中的文件
<li><%= submit_tag 'Save', id: 'submit', :class => 'button' %></li>
在 js 文件中
$(".submit").click(function() {
alert("hi");
event.preventDefault();
health_marks_array = form_hash_and_submit();
if (0 < health_marks_array.length) {
call_form_submit(health_marks_array);
}
else{
location.href = '/thinking_health_card/health_marks/new?form_name=' + form_name + '&student_id=' + student_id + '&health_exam_id=' + health_exam_id
}
return false
});
也尝试过
$(".submit").click(function(event) {
alert("hi");
event.preventDefault();
health_marks_array = form_hash_and_submit();
if (0 < health_marks_array.length) {
call_form_submit(health_marks_array);
}
else{
location.href = '/thinking_health_card/health_marks/new?form_name=' + form_name + '&student_id=' + student_id + '&health_exam_id=' + health_exam_id
}
return false
});
为什么它不起作用?
更改,来自
$(".submit").click(function() {});
自
$("#submit").click(function(event) {
event.preventDefault();
....
});
元素有 id #submit
,而不是类.submit
相关文章:
- jQuery:.click(function(){(element),collapse('show',f
- 具有相同类的jquery-click元素
- 使用Jquery.click显示/隐藏切换,适用于新用户,但不适用于种子
- iframe中的jquery-click元素
- jQuery-click函数不适用于使用innerHTML动态生成的按钮
- addEventListener 在 Javascript 中不起作用,但 jQuery Click 正在工作
- 将参数传递给 jQuery .click WHILE 保留事件参数
- jQuery:click() 执行而不是绑定
- JQuery Click on Table
- jQuery Click Event 不适用于 Angular.js NG-repeat
- SVG 对象部分上的 JQuery click() 不一致
- 防止Jquery.click切换函数因过度点击而反复运行
- JQuery.click,nor.on(“click”,..)与使用函数创建的ASP.NET和twitter boost
- jQuery.click()赢得't从<a>在splash.js模板中
- jQuery.click();不要对特定的元素开火
- Jquery.click阻止默认onClick
- 如何获取从jQuery click()函数调用的特定于标记的自定义Javascript函数
- jQuery click()多次输出错误按钮的信息
- jquery.click()在Ajax 403响应后不起作用
- jQuery .click 在动态加载按钮上不起作用