<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script src="js/knockout-3.0.0.js" type="text/javascript"></script> <script src="js/knockout.mapping-latest.js" type="text/javascript"></script> </head> <body> <input type="text" data-bind="value: xm"/><button onclick="haha();">点击</button> <script type="text/javascript"> var viewModel = { xm: ko.observable("123") }; ko.applyBindings(viewModel); </script> <script type="text/javascript"> function haha() { alert(viewModel.xm); } </script> </body> </html>
我是想将 xm 的是 显示出来.
知道maping可以但是不会弄 请高手明示啊,谢谢
viewModel.xm() 可以了!!呵呵