[英]How to change the CSS property (border color) of input tag of form on button click and also submit data?
[英]Change input border color in Ionic application with button click
我試圖弄清楚,如果我在 html 中輸入了class="mess"
,如何通過按鈕單擊更改 Ionic TypeScript 應用程序中的輸入邊框顏色:
<form>
<ion-item>
<ion-input class="mess"></ion-input>
</ion-item>
</form>
.css
中的默認顏色:
.mess {
border: 2px solid #88ff00;
}
我找不到方法,如何從#88ff00;
更改border
顏色; 不同的顏色#95214b;
點擊:
<ion-button (click)="changeBorderColor()">Change color</ion-button>
我已經嘗試在changeBorderColor()
function 中使用document.documentElement.style.setProperty
,但看起來我必須使用一些不同的方式來獲得結果。
嘗試這個:
<ion-button (click)="changeBorderColor()">Change color</ion-button>
<script>
function changeBorderColor(){
document.getElementById(."mess").style.borderColor = "#95214b";
}
在您的class="mess"
旁邊添加一個id="mess"
並在腳本中顯示getElementById="#mess"
或者您可以使用getElementByClassName=".mess"
或者應該可以正常工作。
你可以試試這個方法...
頁.html文件
<form>
<ion-item>
<ion-input [ngClass]="setBorderColor? 'mess' : ''"></ion-input>
</ion-item>
<ion-button (click)="changeBorderColor()">Change color</ion-button>
</form>
page.ts 文件
public setBorderColor: boolean = false;
constructor() { }
ngOnInit() {
}
changeBorderColor() {
this.setBorderColor = true;
}
page.scss 文件
.mess {
border: 2px solid #88ff00;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.