JQuery可以';找不到我的div元素
我的脚本文件中有jquery函数:JQuery可以';找不到我的div元素,jquery,asp.net,visual-studio-2005,modal-dialog,Jquery,Asp.net,Visual Studio 2005,Modal Dialog,我的脚本文件中有jquery函数: function modalpopup(id) { var searchid = "\"#" + id + "\""; var element = $(searchid ); element.dialog({ height: 340, width: 500, modal: true }); } 在我的as
function modalpopup(id)
{
var searchid = "\"#" + id + "\"";
var element = $(searchid );
element.dialog({
height: 340,
width: 500,
modal: true
});
}
在我的asp.net 2.0文件中,我有以下内容:
<a id="_ctl0_MainContentPlaceHolder_DataGrid1__ctl2_HyperLinkInfo" onclick="modalpopup('_ctl0_MainContentPlaceHolder_DataGrid1__ctl2_details10')">
<img src="../Images/info_icon.PNG" border="0" /></a>
<div id="_ctl0_MainContentPlaceHolder_DataGrid1__ctl2_details10" title="Dialog Title"
style="display: none;">
<center>
<table class="table_class" cellspacing="1" cellpadding="2" rules="all" border="1"
id="_ctl0_MainContentPlaceHolder" style="border-style: None; height: 24px; width: 800px;
font-size: 16px;">
<tr class="table_header_class" style="color: DarkGray; font-weight: bold; font-size: 16px;
white-space: nowrap">
<td style="white-space: nowrap">
customer details </td>
</tr>
</table>
</center>
</div>
客户详细信息
查找div元素看起来像是一个简单的jquery作业,但是jquery结果为null
我做错了什么?
我的html代码中没有错误格式
请提供帮助
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
function modalpopup(id)
{
alert(id);
var searchid = id;
var element = $("#"+searchid );
element.dialog({
height: 340,
width: 500,
modal: true
});
}
</script>
</head>
<body>
<a href="javascript:void(0);" id="_ctl0_MainContentPlaceHolder_DataGrid1__ctl2_HyperLinkInfo" onclick="modalpopup('_ctl0_MainContentPlaceHolder_DataGrid1__ctl2_details10');">
<img src="../Images/info_icon.PNG" border="0" /></a>
<div id="_ctl0_MainContentPlaceHolder_DataGrid1__ctl2_details10" title="Dialog Title"
style="display: none;">
<center>
<table class="table_class" cellspacing="1" cellpadding="2" rules="all" border="1"
id="_ctl0_MainContentPlaceHolder" style="border-style: None; height: 24px; width: 800px;
font-size: 16px;">
<tr class="table_header_class" style="color: DarkGray; font-weight: bold; font-size: 16px;
white-space: nowrap">
<td style="white-space: nowrap">
customer details </td>
</tr>
</table>
</center>
</div>
</body>
</html>
函数modalpopup(id)
{
警报(id);
var searchid=id;
var元素=$(“#”+searchid);
元素对话框({
身高:340,
宽度:500,
莫代尔:对
});
}
客户详细信息
好吧,这是有效的:
这样就可以了
function modalpopup(id) {
var element = $('#'+id);
element.dialog({
height: 340,
width: 500,
modal: true
});
}
试试这个:
function modalpopup(id)
{
$("#"+id).dialog({
height: 340,
width: 500,
modal: true
});
}
为什么要加引号<代码>var searchid=“\”\35;“+id+”\”您正在搜索名为
“#id_name”
的内容,而不是只搜索#id_name
下面和评论中的答案对您有用这是一个深层次的问题。我确实尝试了所有建议,但我的元素仍然为空。我认为这是一个很深的jquery问题。我确实尝试了这里建议的所有元素,但我的元素仍然为null。我的jquery链接可能不对吗?在我的主页上,你可以看到这3行代码:code.jquery.com/jquery-1.9.1.js“>code.jquery.com/ui/1.10.3/jquery ui.js”>还有其他想法吗?我还在“a”标记中添加了an href=“javascript:void(0);”这是一个很好的做法。我使用的是Asp.net 2.0服务器端语言并不重要,呈现的javascript和html是问题所在。我主要改变了3件事,如您所见:1。“a”标签。2.对于javascript函数,此函数的定义必须在“a”标记之前,以便正确加载。3.te src标记中的“http://”内容