我想使用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