Javascript 复制后的方法,为什么?

Javascript 复制后的方法,为什么?,javascript,jquery,ruby-on-rails,simple-form,Javascript,Jquery,Ruby On Rails,Simple Form,我在提交表单时遇到问题,它生成了一个重复的post方法,我不知道为什么,因为我的js中有防止默认值。房间里有Iluminati吗 我的JS <% if @photo.user = current_user %> <script> $("#tp_tag_save").on('click', function(event) { event.preventDefault(); $.post("/users/<%= current_user.id %>/

我在提交表单时遇到问题,它生成了一个重复的post方法,我不知道为什么,因为我的js中有防止默认值。房间里有Iluminati吗

我的JS

<% if @photo.user = current_user %>
 <script> $("#tp_tag_save").on('click', function(event) {
  event.preventDefault();
    $.post("/users/<%= current_user.id %>/photos/<%= @photo.id %>/tags", {
      "tag[name]" : $("#tag_name").val(),
      "tag[location]" : $("#tag_location").val(),
      "tag[price]" : $("#tag_price").val(),
      "tag[coordinate_x]" : $("#tag_coordinate_x").val(),
      "tag[coordinate_y]" : $("#tag_coordinate_y").val()
    }).done(function (data) {
      drawTag($("#tag_name").val(), $("#tag_price").val(), $("#tag_location").val(), $("#tag_coordinate_x").val(), $("#tag_coordinate_y").val()),
      reDrawList();
    });
    modal("#tag_modal", "hide", 200);
  });
</script>
<% end %>

$(“#tp#tag_save”)。在('click',函数(事件){
event.preventDefault();
$.post(“/users//photos//tags”{
“tag[name]:$(“#tag_name”).val(),
“tag[location]:$(“#tag_location”).val(),
“tag[price]:$(“#tag_price”).val(),
“tag[coordinate_x]:$(“#tag_coordinate_x”).val(),
“tag[coordinate_y]:$(“#tag_coordinate_y”).val()
}).完成(功能(数据){
drawTag($(“#tag_name”).val(),$(“#tag_price”).val(),$(“#tag_location”).val(),$(“#tag_坐标_x”).val(),$(“#tag_坐标_y”).val(),
重画列表();
});
模态(“标记模态”,“隐藏”,200);
});
我的表格

<div class="large-5 center semi_padding_top columns large-centered ">
    <h1> <i class="icon-photo"></i>Subir un spot</h1>
    <h6 class="lightgrey thin">Los spots son rincones de tu casa, oficina o negocio de los que estés orgulloso de cómo están decorados. </h6>
    <%= simple_form_for [current_user, @photo] , html_input: "data-abide" do |f| %>
        <div class="new_spot_form deco-form semi_padding_top">
            <%= f.input :title , label: "Ponle un título a tu spot", html_input: "required", class: "input" %>
            <%= f.input :description, label: "¿Qué te gusta de este spot?" , class: "textarea" %>
            <%= f.input :photo, label: "Ahora sube tu foto", input_html: { id: 'fileElem'} %>
            <button id="fileSelect" class="semi_margin_bottom" type="button"><i class="valign-m quarter_padding_right icon-magnifier"></i>Seleccionar spot</button>
            <%= f.label "Selecciona el estilo de tu spot" %>
            <%= f.collection_select :category_id, Category.all, :id, :name%>
            <%= f.label "Selecciona la zona de tu spot" %>
            <%= f.collection_select :zone_id, Zone.all, :id, :name %>
            <%= f.input :terms , label: "Tengo los derechos de esta foto" %>
            <%= f.button :submit, "Subir Spot", input_html: {class: 'icon-magnifier button'} %>
        </div>
    <% end %>
</div>

Subir un spot
这是卡萨咖啡馆的一个景点,它是咖啡馆的一部分,也是咖啡馆的一部分。
选择点

如何调用js代码? 我发现其中有一个错误

<% if @photo.user = current_user %>

如果在循环中使用此代码,它将被调用两次

在这种情况下,重写

<% if @photo.user == current_user %>


控制台中有错误吗?@Pete没有,控制台中没有错误……这真的很奇怪……最常见的原因是事件绑定了两次<代码>$(“#tp_标记_保存”)。在('click',函数(事件){})上。如果该行代码出于任何原因运行了两次,那么使用该ID检查DOM元素将触发两次。确保只绑定事件once@Patrick我知道,但问题是我看不到我在哪里绑定了两次@帕特里克找到了!我在另一个js中有一个切换方法,id是#的,我只是在sublime中搜索了我所有的文件。我不知道是这个还是其他东西复制了这些东西!