如何将文本框内容添加到javascript文件并在其上使用Jquery函数 [英] How to get textbox content to a javascript file and use of Jquery functions on it

查看:76
本文介绍了如何将文本框内容添加到javascript文件并在其上使用Jquery函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在开发一个项目,其中有3个不同用户的登录页面,参数userID和Password保持不变。对于所有3个单独的登录页面,我需要为每个页面编写验证,因此我教会编写JavaScript文件以通常验证文本框ID在所有3个登录页面中保持相同的位置。



所以我将WebFormOne.js文件放入我的项目解决方案中,像往常一样,我把Jquery.js带到我的项目中



然后我把Jquery.js的引用给了像这样的WebFormOne.js

Hello everyone ,
I am working on a project where there are 3 login pages for different user for that the parameter userID and Password remains the same . For all the 3 separate login pages i need to write validation for each page so i taught of writing a JavaScript file to validate commonly where the text box ID''s remains same in all the 3 login pages .

so i took a "WebFormOne.js" file into my project solution and as usual I took Jquery.js to my project

then i gave ref of Jquery.js to "WebFormOne.js"like this

/// <reference path="Jquery.js" />





I我正在获取WebFormOne.js中的所有jquery函数,所以它对我来说不是问题



现在出现实际问题


在aspx页面中
我已经使用了这样的2本教科书



I am getting all the jquery functions in WebFormOne.js so its not a problem to me

now coming to actual problem

in aspx page i have taken 2 textbooks like this

<asp:TextBox ID="txtuserID" runat="server"></asp:TextBox><br/>
 <asp:TextBox ID="txtpassword" runat="server" TextMode="Password"></asp:TextBox><br/>
<asp:Button ID="Button1" runat="server" Text="Login"  

                        OnClientClick="return validateLoginTextBox();" onclick="Button1_Click"/>





其中validateLoginTextBox()是一个写在WebFormOne.js内的方法

代码如下





where "validateLoginTextBox() " is a method written inside then WebFormOne.js
the code is as follows

/// <reference path="Jquery.js" />

function validateLoginTextBox() {
    var validationResult = true;
    var ControlContent = '';
  alert('hi');

ControlContent = $('#<%=txtuserID.ClientID %>').val();

if (ControlContent.length == 0) {
        alert('User ID Required');
       validationResult = false;
   }
ControlContent = $('#<%=txtpassword.ClientID %>').val();
if (ControlContent.length == 0) {
        alert('Password Required');
       validationResult = false;
     }
return validationResult;

}







我收到提示信息HI之后它显示''$''未定义

任何人都可以告诉我怎样才能解决这个问题。





提前致谢



Arun




I am getting the alert message "HI" after that it s showing ''$'' is undefined
Can anybody tell how can i solve this problem .


Thanks in advance

Arun

推荐答案

' #<%= txtuserID.ClientID%>')。val();

if (ControlContent.length == 0 ){
alert(' User ID Required');
validationResult = false ;
}
ControlContent =
('#<%=txtuserID.ClientID %>').val(); if (ControlContent.length == 0) { alert('User ID Required'); validationResult = false; } ControlContent =


' #< ;%= txtpassword.ClientID%>')。val();
if (ControlContent.length == 0 ){
alert(' 需要密码');
validationResult = false ;
}
return validationResult;

}
('#<%=txtpassword.ClientID %>').val(); if (ControlContent.length == 0) { alert('Password Required'); validationResult = false; } return validationResult; }







我收到提示信息HI之后它显示''




I am getting the alert message "HI" after that it s showing ''


''未定义

任何人都可以告诉我如何解决这个问题。





提前致谢



Arun
'' is undefined
Can anybody tell how can i solve this problem .


Thanks in advance

Arun


这篇关于如何将文本框内容添加到javascript文件并在其上使用Jquery函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆