简体   繁体   中英

How to write value of a checkbox to a span when checked?

Using knockoutJs, when either one of my checkboxes is checked, I want it to output a value to a <span> text, like so

-webkit-transition: <span data-bind="text: menuEffect"></span> 0.2s ease-in-out;
-moz-transition: <span data-bind="text: menuEffect"></span> 0.2s ease-in-out;
transition: <span data-bind="text: menuEffect"></span> 0.2s ease-in-out;

My checkboxes:

<div>
    <input type="checkbox" value="max-height" data-bind="checked: menuEffect" />Slide In/Out
</div>
<div>
    <input type="checkbox" value="opacity" data-bind="checked: menuEffect" />Fade In/Out
</div>

I'm trying to output the value of the checkboxes in the span tag, but cant quite get it to work?

My viewModel:

self.menuEffect: ko.observableArray(["max-height", "opacity"]);

Any ideas would be very helpful ?

I think this is what you are trying to achieve: jsfiddle.net/7ZC4v/3

The only thing different is that I changed the : to a =

self.menuEffect= ko.observableArray(["max-height", "opacity"]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM