【发布时间】:2011-05-01 20:46:09
【问题描述】:
我的网站中有一个 Jquery 对话框。此对话框用于获取用户 cmets。目前,我正在使用以下代码来执行 Javascript 函数并且工作正常:
**<a href="#dialog" name="modal">Rate this</a>**
<div id="dialog" class="window"></div>
<div id="mask"></div>
它调用的Javascript代码如下:
$(document).ready(function() {
//select all the a tag with name equal to modal
$('a[name=modal]').click(function(e) {
//Cancel the link behavior
e.preventDefault();
//Get the A tag
var id = $(this).attr('href');
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();
//Set heigth and width to mask to fill up the whole screen
$('#mask').css({ 'width': maskWidth, 'height': maskHeight });
//transition effect
$('#mask').fadeIn(1000);
$('#mask').fadeTo("slow", 0.8);
//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
//Set the popup window to center
$(id).css('top', winH / 2 - $(id).height() / 2);
$(id).css('left', winW / 2 - $(id).width() / 2);
//transition effect
$(id).fadeIn(2000);
});
});
//if close button is clicked
$("input[id$='btnClose']").click(function(e) {
e.preventDefault();
$('#mask').hide();
$('.window').hide();
});
由于 href 没有服务器端点击事件,我需要使用链接按钮调用 javascript。我尝试了几种方法,但都没有得到实际的结果。
要结束,我需要将此调用 **<a href="#dialog" name="modal">Rate this</a>**
更改为链接按钮,以便我可以捕获点击事件。
【问题讨论】:
-
这应该可以工作。即使它没有服务器端点击事件,但您不需要服务器端操作。对话模型将通过 jQuery 在客户端显示。你有什么错误吗?
-
它工作得很好。但我需要在 asp 中使用链接按钮来调用它。在我的网站上,只有注册用户才能对帖子发表评论。使用 Href 调用,我不能这样做。我需要一个链接按钮,以便我可以检查用户是否是注册用户。
-
所以你想在服务器上检查他/她是否被允许评价它,如果是那么运行上面的代码来显示模型?对吗?
-
嗯,你说得对。
-
通过使用链接按钮,我可以做到这一点。如果用户不是注册会员,那么他应该被重定向到 Login.aspx 页面。使用 HREF,我不能这样做。