2014-12-01 61 views
0

我遇到以下问题。下面的代码给了我一个链接来执行删除表中的一行。点击它后禁用<a>

该链接调用确认,以便用户确认是否删除。

我想要做的是在确认<a>变为禁用之后。我该怎么做?

<a class="actionIcon" onclick="if (confirm('Tem a certeza que quer fechar o ticket \&quot;You can \&quot;?')) { var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'post'; f.action = this.href;var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', 'sf_method'); m.setAttribute('value', 'delete'); f.appendChild(m);var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_csrf_token'); m.setAttribute('value', 'cd78fd1b6aa79fa78c338a94951912f2'); f.appendChild(m);f.submit(); };return false;" href="/qdPM/index.php/tickets/delete/id/4162/projects_id/71/redirect_to/ticketsList"><img title="Fechar" class="iconDelete"></a> 
+0

你已经在操纵表单,所以你试图自己解决这个问题? – kero 2014-12-01 17:22:47

+6

我的天啊,为什么地球上都是INLINE?创建一个函数,调用它,并添加一个类来禁用链接!编辑:我的滚动只是自杀。 – briosheje 2014-12-01 17:23:05

+0

大声笑,如果你已经使用onClick ...然后删除一个标签,放在另一个元素上,onClick检查一个var,确认后把var与不同的值和voilà,问题解决了! – 2014-12-01 17:24:21

回答

2

作为一种快速修复,您可以简单地将:this.onclick = function() {return false;}添加到您的事件处理程序中。

但作为一个更强大的解决方案,你真的,真的,真的不应该使用内联事件处理程序,尤其不适合的东西太复杂。

0

与jquery

<a class="actionIcon" id="action"><img title="Fechar" href="/qdPM/index.php/tickets/delete/id/4162/projects_id/71/redirect_to/ticketsList" class="iconDelete"></a> 

$(function() 
{ 
    $("#action").click(function() 
    { 
     if (confirm('Tem a certeza que quer fechar o ticket \&quot;You can \&quot;?')) 
     { 
      var f = document.createElement('form'); 
      f.style.display = 'none'; 
      this.parentNode.appendChild(f); 
      f.method = 'post'; 
      f.action = this.href; 
      var m = document.createElement('input'); 
      m.setAttribute('type', 'hidden'); 
      m.setAttribute('name', 'sf_method'); 
      m.setAttribute('value', 'delete'); 
      f.appendChild(m); 
      var m = document.createElement('input'); 
      m.setAttribute('type', 'hidden'); 
      m.setAttribute('name', '_csrf_token'); 
      m.setAttribute('value', 'cd78fd1b6aa79fa78c338a94951912f2'); 
      f.appendChild(m); 
      f.submit(); 
     } 

     $(this).attr("disabled", true); 
     return false; 
    }); 
}); 
0

1 - CSS>创建有残疾的类;

a.ActiveAnchor { 
    pointer-events: none; 
    cursor: default; 
} 

2-使用jQUERY更改类;

$("#AchorID").toggleClass(className, addOrRemove);