Javascript函数:有些东西不起作用

时间:2013-02-08 05:46:33

标签: javascript asp.net

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

SCRIPT

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;"/>

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

1 个答案:

答案 0 :(得分:2)

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

OnClientClick =“return payment();”