-2

我的应用程序中有一个用于验证表单的 Javascript 函数,我在单击按钮时调用它。但是脚本不起作用。

脚本

function payment() {
  alert("hi");
  var theuser = document.getElementById("<%=txtcardname.ClientID%>").value;
  var thecardno = document.getElementById("<%=txtcreditdet.ClientID%>").value;
  var thecvv = document.getElementById("<%=txtcvv.ClientID%>").value;
  var matchname = theuser.match(userRegex);
  var divcontent = document.getElementById("<%=errorcontent.ClientID%>");
  var msglbl = document.getElementById("<%=lblerror.ClientID%>");
  var ermsg = "";
  /*username validation*/
  if (matchname == null) {
    ermsg += "<li class='logli'>Username is Empty or Invalid.</li>";
  }
  /*Mobile validation*/
  if (themobile.length != 10) {
    ermsg += "<li class='logli'>Enter Your CardNumber Correctly.</li>";
  }
  /*Email validation*/
  if (thecvv.length!=3) {
    ermsg += "<li class='logli'>Enter Ur Cvv Correctly.</li>";
  }
  if (ermsg != "") {
    divcontent.style.display = "block";
    divcontent.style.background-colour="Aqua";
    divcontent.style.border = "1px solid #ff0000";
    divcontent.style.width = "100%";
    divcontent.style.margin = "0px 0 10px 15px";
    msglbl.style.display = "block";
    msglbl.style.margin = "0 0 15px 15px";
    msglbl.innerHTML = "Please correct the below errors" + "<ul>" + ermsg + "</ul>";
    return false;
  }
  return true;
}

ASPX

<asp:Button ID="btnpay" runat="server" Text="PAY" CssClass="btnpaystyle" OnClientClick="if(!payment())return false;"/>

注意:我payment()在按钮的 clientclick 事件中调用该函数。

4

1 回答 1

2

在你的 asp 按钮中试试这个:

OnClientClick="return payment();"

于 2013-02-08T17:47:10.403 回答