Rails jQuery link_to 点击功能问题
提前致谢。
所以我的总体目标是弹出一个带有表单的模式对话框。当我单击链接调出模式时,我遇到了一个问题,它似乎没有使用 javascript ...它只是呈现页面,就好像 javascript 被禁用一样。代码如下:)
application.js
jQuery(function(){
$("#create_reminder_dialog").click(function() {
$('#new_reminder_dialog').dialog('open');
});
// Initialzes Create Reminder Modal Box
$("#new_reminder_dialog").dialog({
autoOpen: false,
height: 350,
width: 350,
modal: true,
buttons: {
'Create New Reminder': function() {
$('#new_reminder').submit();
},
Cancel: function() {
$(this).dialog('close');
}
},
close: function() {
allFields.val('').removeClass('ui-state-error');
}
});
});
我在 Rails
<%= link_to "Create reminder", new_reminder_path, :id=>'create_reminder_dialog' %>
Remembers/new.html.erb
<% form_for :reminder, :url => {:action => "create"}, :html=>{:id=>"new_reminder_dialog"} do |form| %>
<%= form.text_field :description, :class=>"short" %>
<%= form.label :description %>
<%= form.text_field :days, :class=>"short" %>
<%= form.label "Days between interactions" %>
<%= submit_tag "Submit" %><%end>
中的链接在 firebug 中我没有看到像我期望的那样的 GET 请求。
有人提供故障排除提示吗?
Thanks in advance.
So my overall goal is get a modal dialog box with a form in it to pop up. I am running into an issue when I click my link to bring up the modal it doesn't seem to be using javascript ... it just renders the page as if javascript is disabled. Code below :)
application.js
jQuery(function(){
$("#create_reminder_dialog").click(function() {
$('#new_reminder_dialog').dialog('open');
});
// Initialzes Create Reminder Modal Box
$("#new_reminder_dialog").dialog({
autoOpen: false,
height: 350,
width: 350,
modal: true,
buttons: {
'Create New Reminder': function() {
$('#new_reminder').submit();
},
Cancel: function() {
$(this).dialog('close');
}
},
close: function() {
allFields.val('').removeClass('ui-state-error');
}
});
});
My link in rails
<%= link_to "Create reminder", new_reminder_path, :id=>'create_reminder_dialog' %>
reminders/new.html.erb
<% form_for :reminder, :url => {:action => "create"}, :html=>{:id=>"new_reminder_dialog"} do |form| %>
<%= form.text_field :description, :class=>"short" %>
<%= form.label :description %>
<%= form.text_field :days, :class=>"short" %>
<%= form.label "Days between interactions" %>
<%= submit_tag "Submit" %><%end>
In firebug I'm not seeing a GET request like I expect.
Troubleshooting tips anyone??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您只需要在点击函数中返回
false
即可防止触发链接的 href:I'm thinking you'd just need to return
false
in your click function to prevent the link's href from firing: