如何使用.js文件中的javascipt函数并应用于文本框。 [英] how to use javascipt function from .js file and apply to textbox.
问题描述
如何使用.js文件中的javascipt函数,我想将此函数应用于文本框。
例如:我必须这样做...
我的文本框不允许数值。为此我做了功能。这个函数在.js文件中。现在我必须将此函数用于文本框。我不太了解javascript。所以任何人都可以帮助我..
在您的HTML代码中,添加以下内容:
< script type = text / javascript src < span class =code-keyword> = yourJavascriptFile.js > < span class =code-keyword>< / script >
现在,您的外部JavaScript已加载,您可以调用您的函数。
希望这会有所帮助。
>>首先加载js文件,如
< script language = javascript type = text / javascript src = jsfilelocation / filename.js />
>>记住根据验证函数中的条件返回true / false。
例如,在你的js文件中,让我们说有一个名为Validate()的方法来验证文本框。所以函数应该返回true / false
function Validate()
{
// 验证码。
// 如果数字返回true则返回false;
...
}
>>现在在你的提交按钮中写...
< asp:按钮ID = btnSave runat = server CssClass = ActionButton Text = 保存 ValidationGroup = vgAddress
OnClick = btnSave_Click OnClientClick = < span class =code-string> javascript:return Validate();
尝试添加此功能
function isAlphabet(elem){
var alphaExp = / ^ [a-zA -Z] +
how to use javascipt function from .js file and i want to apply this function to textbox.
Ex:I have to do like this...
my textbox not allow numeric values.To do this I have make fuction.This function is in .js file.Now I have to use this function for textbox. I don''t know javascript well.so any one can help me..
Hi,
In your HTML code, add this:
<script type="text/javascript" src="yourJavascriptFile.js"></script>
Now, your external JavaScript is loaded, and you can call your function.
Hope this helps.
>> First of all load the js file like
<script language="javascript" type="text/javascript" src="jsfilelocation/filename.js" />
>> Remeber to return true / false based on the condition in your validation function.
For example, in your js file, let''s say there is a method called Validate() that validates the textbox. SO the function should return true / false
function Validate() { // Validation code. // If numeric return true else return false; ... }
>> Now in your submit button write...
<asp:Button ID="btnSave" runat="server" CssClass="ActionButton" Text="Save" ValidationGroup="vgAddress" OnClick="btnSave_Click" OnClientClick="javascript:return Validate();"
Try adding this function
function isAlphabet(elem){ var alphaExp = /^[a-zA-Z]+
这篇关于如何使用.js文件中的javascipt函数并应用于文本框。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!