未捕获的参考错误:未在HTMLAnchorElement.onclick中定义

时间:2018-05-14 20:50:17

标签: jquery onclick

当我尝试使用数值时,此代码工作正常,但是当我尝试使用AlphaNumeric值时显示错误。

  

未捕获的参考错误:未在HTMLAnchorElement.onclick

中定义
<a onclick="pay_profit(N5S7W4Z5)" id="btn-N5S7W4Z5" class="btn btn-success"> 
<i class="icmn-upload9 margin-right-5"></i> Pay &nbsp;Profit </a>

<script>
function pay_profit(refno)      
  {
    swal({
                    title: "Are you sure?",
                    text: "Do you Really want to Pay Profit to CAIXA!",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#5DC698",
                    confirmButtonText: "Yes, Process it!",
                    cancelButtonText: "No, Cancel It!",
                    closeOnConfirm: false,
                    closeOnCancel: false },
                function (isConfirm) {
                       if (isConfirm) {
                        $.ajax({
                          url:'functions/pay_profit.php',
                          type:"post", 
                          data:{refno:refno},
                          beforeSend: function () {
                              $('#btn-'+refno).hide();
                              swal({
                                title: "Updating Status...",
                                text: "Please wait",
                                type: "info",
                                // imageUrl: "assets/images/caixa-logo.png", 
                                showConfirmButton: false,
                                allowOutsideClick: false
                              });
                            },                              
                          success: function(data)
                          {
                            if(data=="pay")
                            {

                              swal({
                                                title: "Success!",
                                                text: "Pay Profit to CAIXA Successfully.",
                                                type: "success"
                                            });
                              window.location.reload();
                            } else {
                              //alert("Failed");
                              swal({
                                      title: "Error!",
                                      text: "Pay Profit to CAIXA not Cancel... Refrersh the Page.",
                                      type: "error"
                                  });
                              window.location.reload();
                            }
                          }
                        });
                    }else{
                            swal("Cancelled", "Pay Profit Canceled");
                        };
                    });//outer swal        
  }
  <script>

1 个答案:

答案 0 :(得分:0)

如果您尝试将文字字符串传递给onclick中的方法,则必须将其放在引号中,否则javascript会假设您将其视为变量。

<a onclick="pay_profit('N5S7W4Z5')" id="btn-N5S7W4Z5" class="btn btn-success">