我想使用Aurelia檢索所選單選按鈕的值。以下是我的代碼。Aurelia將值綁定到支票更改上的單選按鈕
<input id="account-location-1" name="account-location" type="radio"
value.bind="Item1" checked checked.bind="accountLocation"
click.delegate="toggle()">
<label for="account-location-1">Australian</label>
<input id="account-location-2" name="account-location" type="radio"
value.bind="Item2" checked.bind="accountLocation" click.delegate="toggle()">
<label for="account-location-2">International</label>
export class TestApp{
accountLocation = '';
private toggle() {
alert(accountLocation);
return true;
}
}
問題是accountLocation沒有選中,但始終是一個空字符串。任何指向什麼是錯的?
謝謝,完美的作品。所以,基本上它不起作用,因爲我綁定了字符串值而不是表達式? –
你試圖將單選按鈕的值綁定到一個不存在的變量,這就是爲什麼你得到一個空的結果。要看看它是如何工作的,你可以使用你的舊代碼並創建一個變量:'Item2 =「example」;'然後當你按下按鈕時你的舊代碼將打印「example」。 – greensponge