konckout visible绑定问题

qq_35413026 2017-04-06 10:23:10

<div data-bind="visible:see()==1 " style="display:none" id="test"></div>



问题:当self.see() == 1 的时候 div还是没有显示,查看了官方文档没有具体这方面的问题.
...全文
144 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Hello World, 2017-04-11
  • 打赏
  • 举报
回复
不能直接绑定display,要么绑定css,要么绑定style:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
</head>
<body>
    <div data-bind="style: { display: see() == 1 ? 'block' : 'none' }, html: text" style="display: none;" id="test">Somthing</div>
</body>
</html>
<script src="../../Script/knockout/knockout3.4.0.min.js"></script>
<script>
    var viewModel = {
        see: function () { return 1 },
        text: new Date()
    }
    ko.applyBindings(viewModel);
</script>
qq_35413026 2017-04-10
  • 打赏
  • 举报
回复
那很尴尬的 每次刷新网页的时候 先会显示一下 然后又隐藏 体验很差
Hello World, 2017-04-06
  • 打赏
  • 举报
回复
把style="display:none"去掉

87,994

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧