扩展我没有建立的网站。我希望能够使用参数调用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');
})
});
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();
}
答案 0 :(得分: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();
}
然后
$('a#ShowWindow').click(function(e) {
window.open($(this).attr("href"), 'Info', 'scrollbars=yes,width=510,height=536');
e.preventDefault();
})
这是一种稍微不同的方法,但如果JavaScript不可用,它会降级得更好。
更新(以处理表格中的多个链接)
$('table a').click(function(e) {
window.open($(e.target).attr("href"), 'Info', 'scrollbars=yes,width=510,height=536');
e.preventDefault();
});
答案 1 :(得分:-2)
var strattonn = {};
strattonn.openWindow = function(url, title) {
window.open(url, title, 'scrollbars=yes,width=510,height=536');
return false;
}
public static string ToHtml(this Location location)
{
var html = new StringBuilder();
html.Append("<td><a href='#' onclick='return strattonn.openWindow('MyInfo.aspx', 'My Info')'>Read More</a></td>");
return html.ToString();
}