码迷,mamicode.com
首页 > 其他好文 > 详细

knockout 学习实例6 attr

时间:2016-07-08 23:23:19      阅读:306      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <script src="js/knockout-3.4.0.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<a data-bind="attr: { href: url, title: details }">
    Report
</a>
 
<script type="text/javascript">
    var viewModel = {
        url: ko.observable("year-end.html"),
        details: ko.observable("Report including final year-end statistics")
    };
    ko.applyBindings(viewModel)
</script>
 
</body>
</html>

 

如果属性绑定 data-sonmeth 和css的绑定一样,也需要加入 引号 ‘data-sonmeth‘

下面的会报错

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <script src="js/knockout-3.4.0.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div data-bind="attr: { data-something: someValue }">...</div>

 
<script type="text/javascript">
    var viewModel = {
        someValue: ko.observable("{name:‘data-something‘}"),
       
    };
    ko.applyBindings(viewModel)
</script>
 
</body>
</html>

下面的时正常的

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <script src="js/knockout-3.4.0.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div data-bind="attr: { ‘data-something‘: someValue }">...</div>

 
<script type="text/javascript">
    var viewModel = {
        someValue: ko.observable("{name:‘data-something‘}"),
       
    };
    ko.applyBindings(viewModel)
</script>
 
</body>
</html>

 

knockout 学习实例6 attr

标签:

原文地址:http://www.cnblogs.com/tongchuanxing/p/5654723.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!