如何从另一个* .js扩展$(document).ready函数的范围? [英] How do I extent the $(document).ready function from another *.js?
问题描述
这应该是快速的^ _ ^
我写的是自定义的需要以下内容的控件:
1.要包含的* .js文件。
我从oninit调用了一个RegisterScripts方法,该方法使用Page.ScriptManager来确保添加* .js。没有问题
2.他们需要在$(文件).ready中绑定他们的事件。
我实际上是使用'function pageLoad()'所以我不必担心UpdatePanels等等,但是......
...如何'延伸'函数执行一些我需要绑定每个控件的脚本吗?
我目前有什么:
< ; script type = text / javascript>
function pageLoad(){
bindPasswordControls( DIV [ID $ = 'vtbxNewUserPassword']跨度>);
bindPasswordControls( div [id $ ='vtbxExistingUserPassword']);
bindUserNameControls( div [id $ ='vtbxNewUserUsername']) ;
bindEmailControls( div [id $ ='vtbxNewUserEmail']) ;
bindEmailControls( div [id $ ='vtbxExistingUserEmail']);
...
}
...
< / script>
绑定函数在各个js文件中(custom.password.js,custom.email.js,custom.username.js)
每种类型的控件都是一个用户控件,它呈现整个表单组。以下是控件的示例:
...
< ; vtbx:ValidatedPasswordTextbox runat = server ID = vtbxNewUserPassword
标签 = 密码 LabelClass = col-sm- 2
InputGroupClass = col-sm-10 InputGroupAddon = Pw / >
<! - 将呈现为(大致) - >
< div id = < span class =code-keyword> content1 $ othersuff $ vtbxNewUserPassword class = form-group >
< div class = COL-SM-2 - ;
< label for = content1 $ othersuff $ vtbxNewUserPassword_input class = control-label > 密码< / label >
< / div >
< div < span class =code-attribute> class = input-group col-sm-10>
< span class = input-group-addon > Pw < / span >
< 输入 type = text class = form-control > ;
< / div >
< / div
...
现在我已将此标记转换为用户控件,我想确保控件交易将全部用完自己的剧本。他们添加了他们需要的.js文件,但我不知道如何将绑定事件添加到pageLoad()。这是我需要帮助的地方。
我有点像javascript noobie所以我甚至不确定是否正确术语搜索:S
谢谢^ _ ^
(如果你想看到任何代码,请告诉我。我在这里寻找一个非常一般的答案,所以我不确定它是否相关。)
< blockquote>(document).ready。
我实际上正在使用'function pageLoad()'所以我不必担心UpdatePanels等等,但是...
...如何'扩展'函数执行一些我需要绑定每个控件的脚本?
我是什么目前有:
< script type = text / javascript>
function pageLoad(){
bindPasswordControls( DIV [ID
= 'vtbxNewUserPassword']跨度>);
bindPasswordControls( div [id
='vtbxExistingUserPassword'] 跨度>);
bindUserNameControls( div [id
Hi,
This should be a quick one ^_^
I am writing custom controls that require the following:
1. A *.js file to be included.
I have a "RegisterScripts" method being called from the oninit that uses the Page.ScriptManager to ensure that the *.js is added. No issue there
2. They need to have events bound to them in the $(document).ready.
I'm actually using 'function pageLoad()' so I don't have to worry about UpdatePanels and such, but...
... How to I 'extend' the function to perform some script I need to bind each control?
What I have currently:
<script type=text/javascript>
function pageLoad(){
bindPasswordControls("div[id$='vtbxNewUserPassword']");
bindPasswordControls("div[id$='vtbxExistingUserPassword']");
bindUserNameControls("div[id$='vtbxNewUserUsername']");
bindEmailControls("div[id$='vtbxNewUserEmail']");
bindEmailControls("div[id$='vtbxExistingUserEmail']");
...
}
...
</script>
the bind functions are in the individual js files (custom.password.js, custom.email.js, custom.username.js)
each type of control is a usercontrol that renders the whole form-group. Here is an example of the control:
...
<vtbx:ValidatedPasswordTextbox runat="server" ID="vtbxNewUserPassword"
Label="Password" LabelClass="col-sm-2"
InputGroupClass="col-sm-10" InputGroupAddon="Pw"/>
<!-- which will render out as (roughly) -->
<div id="content1$othersuff$vtbxNewUserPassword" class="form-group">
<div class="col-sm-2>
<label for="content1$othersuff$vtbxNewUserPassword_input" class="control-label">Password</label>
</div>
<div class="input-group col-sm-10>
<span class="input-group-addon>Pw</span>
<input type="text" class="form-control">
</div>
</div
...
Now that I have turned this markup into user controls, I want to make sure that the control deals will all of it's own script. They add the .js file they need but I do not know how to add the bind events to pageLoad(). This is where I need help.
I'm a bit of a javascript noobie so I'm not even sure of the correct terminology to search for :S
Thanks ^_^
(let me know if you would like to see any code. I'm looking for a very general answer here so I'm not sure it would be relevant.)
解决方案 (document).ready.
I'm actually using 'function pageLoad()' so I don't have to worry about UpdatePanels and such, but...
... How to I 'extend' the function to perform some script I need to bind each control?
What I have currently:
<script type=text/javascript>
function pageLoad(){
bindPasswordControls("div[id
='vtbxNewUserPassword']"
);
bindPasswordControls("div[id
='vtbxExistingUserPassword']"
);
bindUserNameControls("div[id
这篇关于如何从另一个* .js扩展$(document).ready函数的范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!