1

我在每个表格行中都有一个链接,可以更详细地查看记录。我想添加方法来查看pdf我们为每条记录生成的不同 's,而不会过多地增加表格。我为不同的点击条件绑定了不同的事件,但我遇到了一些问题。首先,它不会pdf像通常从硬链接那样进行,它会打开保存对话框。其次,一旦我告诉它不要保存,页面就不会跟随任何pdf链接。我究竟做错了什么?我认为阻止默认设置可能会chrome在看到按键+单击时停止执行特殊活动,我什至不确定这是开始的问题。奇怪的是,在我之后,例如,ctrl-click页面不会做任何事情,而是mouseover显示“href”是ctrl-click修改后的位置,然后定期点击会做我想要它首先做的事情。

查看代码,我可以明白为什么它正在做它正在做的事情。阻止默认值会阻止 chrome 保存,就像我想要的那样。就像我告诉它的那样,href 已更改。现在我必须点击链接。如果我在收到任何回复之前偶然发现答案,我会回答。

$(".doThings").click(function(e){ 
    var ID = $(this).text();
    if(e.ctrlKey){
        event.preventDefault();
        $(this).attr("href", "http://foo.com/report.php?id="+ID);
    } 
    else if(e.altKey) {
        event.preventDefault();
        $(this).attr("href", "http://foo.com/r30.php?id="+ID); 
    } 
    else if(e.shiftKey) { 
        event.preventDefault();
        $(this).attr("href", "http://foo.com/r45.php?id="+ID); 
    } 
}); 
4

2 回答 2

1

改为使用window.location.href

$(".doThings").click(function(e){ 
    var ID = $(this).text();
    if(e.ctrlKey){
        event.preventDefault();
        window.location.href = "http://foo.com/report.php?id="+ID;
    } 
    else if(e.altKey) {
        event.preventDefault();
        window.location.href = "http://foo.com/r30.php?id="+ID; 
    } 
    else if(e.shiftKey) { 
        event.preventDefault();
        window.location.href = "http://foo.com/r45.php?id="+ID; 
    } 
}); 
于 2012-12-21T13:07:23.450 回答
0

更改href 不是要走的路。我刚刚做了一个javascript重定向。

if(e.ctrlKey){
        e.preventDefault();
        window.location = ("http://foo.com/report.php?id="+ID);
    } 
于 2012-12-21T13:12:02.287 回答