English 中文(简体)
.click()没有工作。 Jquery
原标题:.click() not working. Jquery

在我的日志中,我试图在 but子的点击上进行简单的客户方验证(核对用户名称和密码场是空洞的)。 但是,吉克里的点火不是发射的。 如果是错的话。

注:我有一个活动记录仪表显示,该代码具有某些功能。

<script src="Scripts/Login.js" type="text/javascript"></script>

 <td align="right" colspan="2">
     <asp:Button ID="LoginButton" runat="server"  Text="Log In" 
       onclick="LoginButton_Click" class ="validateForm" />
</td>

Mylogin.js案:

$(function () {

  $( #LoginButton ).click(function () {

            var username = $( #txtUserName );
            var pwd = $( #txtPassword );
            if (username.val().length <= 0) {
                alert("User Name is required.");
                return false;
            }
            if (pwd.val().length <= 0) {
                alert("Password is required.");
                return false;
            }

        });
});

预 收

BB

问题回答

<代码>$(”#<%=LoginButton。 用户信息库 %>”不处理外部 Java本文档。 如果你想要使用外部档案,就会在 as本档案中产生一个全球性的变数,并查阅。


Edit:

在x中形成全球变量。

varloginButtonId = <%=LoginButton。 客户信息%>

用于Java 文件

$("#" + loginButtonId ).click(function () {...});

<><>>>>>指: 变数应在加入提及 Java本前申报。

这不应给你带来任何问题,我们利用 j子挑选的ors子,以 Log子为终点。

$(function () {
  $("input[id$=LoginButton]").click(function () {

            var username = $("input[id$=txtUserName]");
            var pwd = $("input[id$=txtPassword]");
            if (username.val().length <= 0) {
                alert("User Name is required.");
                return false;
            }
            if (pwd.val().length <= 0) {
                alert("Password is required.");
                return false;
            }

        });
});

because in your .js file, javascript couldn t read the value of this: $("#<%= LoginButton.ClientID %>")
You need to: - Put this code at the end of your html page.
OR
- Put a fixed selector in the js file

<代码># CarloinButton 确实有t。 当 as子拿到时,它就会被带入一个与ASP控制有关的专门身份证,如<代码>ctrl00_my Control_panelid_LoginButton。 你们需要做些什么才能将此纳入外部档案,是使用全球变量:

var loginButtonID;
var txtUserNameID;
var txtPasswordID;

$(function () {

  $(loginButtonID).click(function () {

            var username = $(txtUserNameID);
            var pwd = $(txtPasswordID);
            if (username.val().length <= 0) {
                alert("User Name is required.");
                return false;
            }
            if (pwd.val().length <= 0) {
                alert("Password is required.");
                return false;
            }

        });
});

然后在档案中添加这一标识。 j 档案,你需要通过打电话确定这些变量:

<script type="text/javascript">

loginButtonID =  <%=LoginButton.ClientID%> ;
txtUserNameID =  <%=txtUserName.ClientID%> ;
txtPasswordID =  <%=txtPassword.ClientID%> ;

</script>

保证不以新的“老” mo变者重新宣布。 这可能会破坏范围,篡改你的文本。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签