Dav*_*Fox 4 javascript data-binding knockout.js
此页面呈现时选择了正确的单选按钮,但是当选择"sendemail"或"sms"单选按钮值时,应显示其他输入,对吗?
$(function () {
var rbViewModel = {
qrType: ko.observable('plaintext')
};
ko.applyBindings(rbViewModel);
});
Run Code Online (Sandbox Code Playgroud)
然后我的单选按钮
<input type="radio" name="txtType" value="plaintext" data-bind="checked: qrType" />Plaintext
<input type="radio" name="txtType" value="sendemail" data-bind="checked: qrType" />Send E-mail
<input type="radio" name="txtType" value="sms" data-bind="checked: qrType" />SMS
Run Code Online (Sandbox Code Playgroud)
我的意见:
<div data-bind="visible: qrType == 'sendemail'"><input type="text" id="txtEmailSubject" placeholder="E-mail subject" /></div>
<div data-bind="visible: qrType == 'sendemail'"><input type="text" id="txtEmailBody" placeholder="E-mail body" /></div>
<div data-bind="visible: qrType == 'sms'"><input type="text" id="txtSmsMsg" placeholder="SMS body" /></div>
Run Code Online (Sandbox Code Playgroud)
div元素上的属性有问题吗?我认为函数可以在每个KnockoutJS 文档的可见绑定中使用,如下所示:
data-bind="visible: qrType=='sendemail'"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1536 次 |
| 最近记录: |