简体   繁体   English

一键双击

[英]double action in one click jquery

I have problem using onClick, in the first click run one action for the second click the problem showing my click run two action and for the third click the action run three action and for the next click. 我在使用onClick时遇到问题,在第一次单击中为第二次单击运行一个动作,在显示我的单击运行二个动作的问题中,对于第三次单击,该动作运行了三个动作,对于下一次单击,出现问题。 whats the problem white my jquery? 我的jQuery出了什么问题?

My Button Click 我的按钮点击

<a id="detailproduct" href="'.URL.'#PopProductDetail" onclick="showdetailproduct('.$val->bid.')" data-toggle="modal">'.$val->product name.'</a>

this the code 这是代码

<script type="text/javascript">
    function showdetailproduct(id){
    $('#PopProductDetail').on('shown.bs.modal',function(e) {
        utils.ViewPopProduct(id);
    });
    }

var utils = {};
    (function ($) {

          $.ajaxSetup({"error":function(XMLHttpRequest,textStatus, errorThrown) {
              alert(textStatus);
              alert(errorThrown);
              alert(XMLHttpRequest.responseText);

          }});

        utils.ViewPopProduct =  function ViewPopProduct(id) {
            var data={id:id};
            $.ajax({
                type:"GET",
                datatype:"json",
                url:"",
                data:data,
                datatype:"html",
                cache:false,
                success: function(data) {
                        data = JSON.parse( data ); 
                        $('#code').val(data.code);
                        $('#name').val(data.name);
                        $('#groupname').val(data.groupname);
                        $('#brand').val(data.brand);

                        $('#PopProductDetail').trigger("reset");
                        $("#detailproduct").unbind("click", ViewPopProduct);
                }
            });
        return false;
    };

    })(jQuery, window, document);

</script>

The Action url 动作网址

http://example.com/product?id=34&_=1450341040382

Thanks 谢谢

In your showdetailproduct method, you are subscribing one more time to the event: 在您的showdetailproduct方法中,您需要再订购一次该事件:

$('#PopProductDetail').on('shown.bs.modal',function(e) {

This subscription should occur only one. 此订阅只能发生一次。 Put the binder on document.ready . 将活页夹放在document.ready Onclick event is not necessary, the href is doing the trick. Onclick事件不是必需的,href可以解决问题。

This is my Code if it is help full to you. 如果对您有帮助,这就是我的代码。

I can handle 2 function at one click 一键处理2个功能

Html Code HTML代码

 <input type="button" id="btnSave2" value="INSERT-UPDATE" title="Save" 
                onclick="return btnSave2_onclick()" />

 function btnSave2_onclick() 
 {

      var txtcategorycodeid = $("#txtcategorycodeid").val();
      var txtcategoryname = $("#txtcategoryname").val();
      var fuimg = $("#fuimg").val();
      var ddstatus = $("#ddstatus").val();
      var fuimgst;
      if (fuimg != '' ) {
          fuimgst = 'active';
      }
      if (fuimg == '') {
          fuimgst = 'inactive';
      }


      if (txtcategorycodeid == '' && txtcategoryname == ''
            && ddstatus == '---Select---') {

          alert("Enter All Fields");
          return false;

      }
      else {

          if (txtcategorycodeid == '') {
              alert("Enter categorycodeid");

              return false;
          }
          if (txtcategoryname == '') {

              alert("Req  categoryname");

              return false;
          }
          if (!txtcategoryname.match(/^[a-zA-Z]+$/)) {
              alert('categoryname Only alphabets are allowed');
              return false;
          }


          if (ddstatus == '---Select---') {
              alert("Enter status");

              return false;
          }
      }


      var fileUpload = $("#fuimg").get(0);
      var files = fileUpload.files;
      var test = new FormData();
      for (var i = 0; i < files.length; i++) {
          test.append(files[i].name, files[i]);
      }
      $.ajax({
          url: "imguploadhandler.ashx",
          type: "POST",
          contentType: false,
          processData: false,
          data: test,
          // dataType: "json",
          success: function (result) {




      $.ajax({
          type: "POST",
          url: "JKS_Service.asmx/productcategor1",
          data: "{categoryCodeId: '" + txtcategorycodeid + "'       ,categoryName:'" + txtcategoryname + "',status:'" + ddstatus + "',fupic:'"+fuimgst+"'}",
          contentType: "application/json; charset=utf-8",
          datatype: "jsondata",
          async: "true",
          success: function (response) {
              $(".errMsg ul").remove();
              var myObject = eval('(' + response.d + ')');
              if (myObject > 0) {

                  alert("Data saved successfully...");

              }
              else {

                  alert("Not saved..");
              }

              clear();

          },
          error: function (response) {
              alert(response.status + ' ' + response.statusText);
          }
      });
  },


  });
  }

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

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