2016-12-12 49 views
0

我有一個引導程序導航選項卡與4個鏈接(申請人,Coverages,位置,溢價)。我在Coverages上有一個jQuery點擊事件來驗證申請人數據。如果失敗,顯示sweetalert並留申請人標籤:SweetAlert與引導程序導航選項卡

$('#CoveragesTab').off('click').on('click', function (event) { 
    SaveApplicantTabData(function (retVal) { 
     if ("success" == retVal.status) { 
     } 
     else if ("failed" == retVal.status) { 
      event.stopImmediatePropagation(); 
      swal(retVal.message, "Applicant Error", "error"); 
      //alerta(retVal.message); 
      return false; 
     } 
     else if ("error" == retVal.status) { 
      event.stopImmediatePropagation(); 
      alert(retVal.message); 
      return false; 
     } 
    }); 
}); 

功能上講,這種完美的作品,但覆蓋範圍鏈接看起來像它仍然具有焦點 - 標籤的整個廣場被高亮顯示一樣懸停一個標籤。它沒有重點。我使用開發人員工具進行了檢查,並且主動鏈接正確以及其他值。

如何從標籤中刪除聚焦的外觀?

謝謝。

回答

0

您可以添加blur()方法您Coverages導航標籤鏈接驗證failes時:

$('#CoveragesTab').off('click').on('click', function (event) { 
    SaveApplicantTabData(function (retVal) { 
     if ("success" == retVal.status) { 
     } 
     else if ("failed" == retVal.status) { 
      event.stopImmediatePropagation(); 
      swal(retVal.message, "Applicant Error", "error"); 
      //alerta(retVal.message); 
      $(this).blur(); 
      return false; 
     } 
     else if ("error" == retVal.status) { 
      event.stopImmediatePropagation(); 
      alert(retVal.message); 
      return false; 
     } 
    }); 
}); 
+0

這沒有奏效。我也試過$(this).focus()。沒有運氣。但是謝謝你! – FirstByte

+0

它爲我工作,我試過這yestreday。 – makshh

+0

我也試過$(「#ApplicantLink」)。addClass('active'); – FirstByte

0

大量的試驗和錯誤之後,我終於想通了。我必須同時使用event.stopImmediatePropogation和.blur()。

$('#CoveragesTab').off('click').on('click', function (event) { 
    SaveApplicantTabData(function (retVal) { 
     if ("success" == retVal.status) { 
     } 
     else if ("failed" == retVal.status) { 
      event.stopImmediatePropagation(); 
      $('#CoveragesTab').blur(); 
      swal(retVal.message, "Applicant Error", "error"); 
      return false; 
     } 
     else if ("error" == retVal.status) { 
      event.stopImmediatePropagation(); 
      alert(retVal.message); 
      return false; 
     } 
    }); 
}); 

的唯一的事情是,當你使用stoppropogation,它留下的HREF作爲URL的一部分:

http://localhost:3858/CreateQuote/EditQuote/1#coverages-tab 

所以我必須從網址中去除報價ID。

有誰知道如何防止這種情況發生?

謝謝。