我项目中的页面基于主页面和内容页面...
我想在其中一个内容页面中使用 javascript(而不是 jquery)做一些事情 所有主元素和内容元素都已完全加载。(例如,将焦点设置在 RadComboBox 控件上)
为此,我使用了以下代码:
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script src="../JQuery/jquery-1.4.1.js" language="javascript" type="text/javascript"></script>
<script type="text/javascript">
onload = onloadOfDocument;
function onloadOfDocument() {
var combo = $find("<%= RadcbPersonelCompleteNameInvwNoskhehEdit.ClientID %>");
alert(combo);
var comboInput = combo.get_inputDomElement();
comboInput.focus();
}
</script>
</asp:Content>
但是alert(combo);
始终返回 null。($find
代码用于 telerik 控件,上面有关 telerik 控件的代码完全正确)
解决这个问题null
问题我测试如下所示的方式:
1- 我从主页面和内容页面中删除了除 RadComboBox 控件之外的所有控件,空问题消失了,所以我得出空问题是关于主页面和内容页面的所有元素在
$find("<%= RadcbPersonelCompleteNameInvwNoskhehEdit.ClientID %>");
被解雇了。
2- 所以我用了
$(document).ready(function() { my codes });
代替
onload = onloadOfDocument;
但问题没有解决 - 我不知道为什么!!!
3- 最后我测试了下面的代码,它运行良好:
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script src="../JQuery/jquery-1.4.1.js" language="javascript" type="text/javascript"></script>
<script type="text/javascript">
//onload = onloadOfDocument;
document.onkeyup = onkeyupOfDocument;
function onkeyupOfDocument() {
var combo = $find("<%= RadcbPersonelCompleteNameInvwNoskhehEdit.ClientID %>");
alert(combo);
var comboInput = combo.get_inputDomElement();
comboInput.focus();
}
</script>
在所有主元素和内容元素都完全加载之后,我应该使用什么文档函数来执行一些 javascript 代码?
提前致谢
最佳答案
下面的链接解决了我的问题: $(document).ready() and pageLoad() are not the same!
我的答案 -> 使用 pageLoad() 而不是 $(document).ready()
关于javascript - $(document).ready(function() 在内容页面/Telerik 控件中不能完美运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3306914/