简体   繁体   English

调用特定的div onclick

[英]Calling a specific div onclick

I'm having more than two forms my page and with one i've there's a script attached that onsubmit it should show a successful message in a div. 我的页面有两个以上的表单,有一个表单附加了一个脚本,该脚本在onsubmit上应该在div中显示成功消息。 But when i click on any of the submit buttons on the page, the successful message in the div shows up. 但是,当我单击页面上的任何提交按钮时,将显示div中的成功消息。 this is my code 这是我的代码

<script>
$(document).ready(function(){
    $("form").on('submit',function(event){
        event.preventDefault();

        data = $(this).serialize();

        $.ajax({
        type: "POST",
        url: "insert_call_love.asp",
        data: data
        }).success(function() {

            $("#feedback").append("<div class='messages' style='border:1px purple solid; padding:2px; margin:5px;'>You have Loved this photo</div>");

            setTimeout(function() { 
                $(".messages").fadeOut(function(){
                    $(".messages").remove();
                }); 
            }, 1000);

            $("input[type=text]").val("");

        });
    });
});
</script>

and someone told me to change from the one above to this: 有人告诉我将以上内容更改为:

<script>
$(document).ready(function(){
    $("form3").on('submit',function(event){
        event.preventDefault();

        data = $(this).serialize();

        $.ajax({
        type: "POST",
        url: "insert_call_love.asp",
        data: data
        }).success(function() {

            $("#feedback").append("<div class='messages' style='border:1px purple solid; padding:2px; margin:5px;'>You have Loved this photo</div>");

            setTimeout(function() { 
                $(".messages").fadeOut(function(){
                    $(".messages").remove();
                }); 
            }, 1000);

            $("input[type=text]").val("");

        });
    });
});
</script>

HTML 的HTML

<form id="form3" name="form3" method="POST" action="<%=MM_editAction%>">
          <input type="image" name="imageField2" id="imageField2" src="imgs/buttons/loveit.png" />
          <input name="lemail" type="hidden" id="lemail" value="1" />
          <input name="lfname" type="hidden" id="lfname" value="2" />
          <input name="lpic" type="hidden" id="lpic" value="3" />
          <input name="lresp_email" type="hidden" id="lresp_email" value="4" />
          <input name="lwardr" type="hidden" id="lwardr" value="5" />
        </form>

specifying the form_id for example my formid is form3 but with that when i even click on submit it doesn't even work 指定form_id,例如我的formid是form3,但是当我什至单击提交时,它甚至无法正常工作

Replace the JQuery 'on submit' from: 从以下位置替换“提交时”的JQuery:

$("form3").on('submit',function(event)

to this: 对此:

 $("#form3").on('submit',function(event)

PS: Make sure that the id is unique in the page PS:确保ID在页面中是唯一的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM