[英]Enabling/Disabling onsen Button
我想在其他按鈕的單擊事件上啟用/禁用溫泉按鈕。 我為此使用了以下代碼,但對我沒有用。 需要相同的建議/更正。
<ons-button id="save" disabled="true">Save</ons-button>
<ons-button id="edit" ng-click ="edit_click()">Edit</ons-button>
<ons-button id="cancel" disabled="true">Cancel</ons-button>
javascript:
function edit_click(){
document.getElementById("save").disabled="false";
document.getElementById("cancel").disabled="false";
}
您可以使用ngAttrDisabled
指令動態禁用按鈕。
<ons-button ng-attr-disabled="{{ disableButton }}">Click me!</ons-button>
<input type="checkbox" ng-model="disableButton">
不幸的是, ngDisabled
在當前版本的Onsen UI中不適用於<ons-button>
標記。
您正在評估“假” string
值而非boolean
值...
function edit_click(){
document.getElementById("save").disabled=false;
document.getElementById("cancel").disabled=false;
}
在angularjs文檔中有一個使用ng-disable指令的正確示例: https ://docs.angularjs.org/api/ng/directive/ngDisabled
您可以嘗試類似的溫泉:
<input type="checkbox" ng-model="checked"><br/>
<ons-button ng-model="button" disabled="{{checked}}">Button</button>
如果您使用的是角度,則操作簡單可靠。 以下代碼對我有用,請查看=)
HTML
<ons-button modifier="outline" style="width: 100%; ng-disabled="isDisable">Print</ons-button>
<ons-button modifier="outline" style="width: 100%; ng-disabled="isDisable">Email</ons-button>
JS
//to disable
$scope.isDisable = true;
//to enable
$scope.isDisable = false;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.