调用Javascript函数

str*_*onn 0 javascript jquery

扩展我没有建立的网站.我希望能够使用参数调用ShowWindow proc.我该怎么办?JQuery和Javascript的新手.

default.aspx

<script type="text/javascript" src="/scripts/jquery-1.2.6.js"></script>
<script type="text/javascript">

$(document).ready(function() {
    $('a#ShowWindow').click(function() {
        window.open("TerminalInfo.aspx?", 'Info', 'scrollbars=yes,width=510,height=536');
    })
});
Run Code Online (Sandbox Code Playgroud)

default.aspx.cs

动态构建aspx ...

    public static string ToHtml(this Location location)
    {
        var html = new StringBuilder();

        html.Append("<td><a href='#' id='ShowWindow'>ShowLetter</a></td>");              //This works
        html.Append("<td><a href='#' id='ShowWindow(\"MyInfo.aspx\")'>Read More</a></td>"); //How can I do this? It doesn't work.

        return html.ToString();
    }
Run Code Online (Sandbox Code Playgroud)

Dan*_*iel 6

public static string ToHtml(this Location location)
{
    var html = new StringBuilder();

    html.Append("<td><a href='MyInfo.aspx' id='ShowWindow'>Read More</a></td>");

    return html.ToString();
}
Run Code Online (Sandbox Code Playgroud)

然后

$('a#ShowWindow').click(function(e) {
    window.open($(this).attr("href"), 'Info', 'scrollbars=yes,width=510,height=536');
    e.preventDefault();
})
Run Code Online (Sandbox Code Playgroud)

这是一种稍微不同的方法,但如果JavaScript不可用,它会降级得更好.

更新(处理表中的几个链接)

$('table a').click(function(e) {
    window.open($(e.target).attr("href"), 'Info', 'scrollbars=yes,width=510,height=536');
    e.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)