2017-10-16 24 views
-1

我有幾個<i>元素與glyphicons,我希望他們被觸發,當我按ENTER鍵。我正在使用Angular 2 我該怎麼做?如何在不聽按鍵的情況下使<i>元素可點擊?

<i class="glyphicon glyphicon-menu-down down" 
        *ngIf="!(sort.name === 'Last Name' && sort.order > 0)" (click)="sortTrips('name')" ></i> . 
+0

嘗試附加'click'事件。 –

+0

Roy

+0

對不起,我的問題是不完整的。我希望按下ENTER鍵時可以用鍵盤訪問點擊事件。我已經閱讀了幾篇文章,但我發現的唯一解決方案是聽按鍵。 – Nelul

回答

1

我我找到了答案(僅適用於Angular 2):

<div (keyup.enter)="function()"> 
<i class="glyphicon glyphicon-menu-down down"><i> 
</div> 

在這種情況下,應用程序按照插入的方式工作。

0

嘗試創建像@HassanIman事件說它看起來像:

<!DOCTYPE html> 
 
<html> 
 
<body> 
 

 
<p>This example demonstrates how to assign an "onclick" event to a p element.</p> 
 

 
<p id="demo" onclick="myFunction()">Click me.</p> 
 

 
<script> 
 
function myFunction() { 
 
    document.getElementById("demo").innerHTML = "YOU CLICKED ME!"; 
 
} 
 
</script> 
 

 
</body> 
 
</html>

您嘗試看看在這個網站上的完整爲例:W3SCHOOLS ONCLICK EVENT

+0

https://alligator.io/angular/binding-keyup-keydown-events/。在這裏你可以找到更多的細節 – Nelul

相關問題