0

我的脚本文件中有 jquery 函数:

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>

它看起来像是一个简单的 jquery 工作来查找 div 元素,但 jquery 结果为空!!

我在这里做错了什么?我的html代码中没有错误格式

请帮忙

4

3 回答 3

1
<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>

好吧,这行得通:

http://jsfiddle.net/eorozco/SbGQa/

于 2013-08-17T06:34:47.333 回答
0

this will do the trick

function modalpopup(id) {
    var element = $('#'+id);
    element.dialog({
        height: 340,
        width: 500,
        modal: true
    });
}
于 2013-08-17T06:41:16.487 回答
0

Try this:

function modalpopup(id) 
    {

        $("#"+id).dialog({
            height: 340,
            width: 500,
            modal: true
        });

    }
于 2013-08-17T06:45:37.407 回答