javascript - $(document).ready(function() 在内容页面/Telerik 控件中不能完美运行

标签 javascript asp.net jquery null document-ready

我项目中的页面基于主页面和内容页面...

我想在其中一个内容页面中使用 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/

相关文章:

c# - 使用保存到内存流的图像导出文件

php - 表单提交后jquery移动页面刷新

javascript - onclick 中的字符串

javascript - 从 Django View 打开新选项卡的命令

javascript - 按下Javascript中的按钮后如何重新聚焦在文本字段中的位置?

asp.net - 访问 ListView 的 edititemtemplate 中的控件

php - 使用 ajax 将 javascript 变量传递给 php,结果不显示任何内容

html - 如何以这种格式在 GridView 页脚和 ItemTemplate 中格式化数字 ("###,###.000")

javascript - 表单输入掩码以获得更漂亮的数据

javascript - 如何只显示多个下拉值数组中的1个?