【发布时间】:2010-11-18 17:38:59
【问题描述】:
我正在尝试使用 document.ready 将一些 jquery 附加到网格视图中的复选框:
$(document).ready(function()
{
var chkBox= document.getElementById("gvTimeSheet_ctl01_chkAll1");
//I can alert chkBox.id, element exists
var name = $("input[name='gvTimeSheet$ctl01$chkAll1']");
//Here, when I alert the id, I get a null
var ID = $("#gvTimeSheet_ctl01_chkAll1");
//Here, when I alert the id, I get a null
var withClass = $(".chkAll1Class");
//Here, when I alert the id, I get a null
var withClass2 = $(".Bill1");
//Here, when I alert the id, I get a null
//This line causes the browswer to crash and gives me the following error
//Microsoft JScript runtime error: 'null' is null or not an object
$("#gvTimeSheet_ctl01_chkAll1").click(function()
{
var checked_status = this.checked;
$("input[class=Bill1]").each(function()
{
this.checked = checked_status;
});
});
});*/
那么,为什么尝试在 jquery 中查找 null 对象,却存在于同一方法中的常规 javascript 中?我在这里想念什么。我在此方法正上方的脚本标记中引入了 jquery js 文件。我似乎无法使用 jquery 在此页面上找到任何对象。在其他页面上,我可以。
【问题讨论】:
-
你在使用其他的 Javascript 库吗?
-
你能贴出生成的 HTML 源代码吗?也许在jsbin.com 发布一个沙盒会有助于理解。
标签: asp.net jquery gridview checkbox