我有一個要求,當單擊一個元素(Button)時應該改變另一個元素屬性。 我可以通過jquery來完成。但我想忽略我的角度項目中的jQuery。通過angularjs中的另一個元素獲取元素
在HTML中,
<input type=password />
<button ngclick="changeToTxt()">Change type password to text</button>
在控制器,
app.controller('loginPage', function ($scope) {
$scope.changeToTxt = function() {
**// need to get the password element and need to change type = text.....**
}
});
有沒有一種方法(或不同的/最好的方法)由控制器做什麼?或者需要爲此寫一條指令?
這是跨瀏覽器兼容嗎?我認爲它不適用於IE。你有沒有在不同的瀏覽器上試過它? – user1537766 2014-12-03 06:51:25
是的。我已在所有平臺上進行過測試。它將一切工作。 – simon 2014-12-03 06:54:06
適用於IE9及以上版本,不在下面http://www.universalwebservices.net/web-programming-resources/javascript/change-input-element-type-using-javascript – 2014-12-03 07:03:17