問題描述
當按鈕向右浮動時,ng‑click 不起作用 (ng‑click doesn't work when the button is floated to the right)
好吧,這真是一個奇怪的問題。
我在一個 Angular 項目中工作,我有一個帶有 ng‑click 的按鈕。它不火。如果我刪除將按鈕浮動到右側的 css,那麼它可以正常工作。
HTML:
<button id="btn" ng‑click="myFunction()">Name</button>
CSS:
button {
float: right;
background‑color: green;
color: white;
}
Javascript / Angular 控制器:
app.controller('HomeController', function($scope) {
$scope.myFunction = function() {
console.log('Hello World');
};
});
只需將 CSS 更改為:
button {
background‑color: green;
color: white;
}
讓它再次工作
參考解法
方法 1:
I think when you float it to the right, some other html is on top of your button and it's preventing you from making the click.
Add a z‑index: 9999 to your button's css
Hope it helped :)
(by dylankbuckley、atefth)