简体   繁体   中英

Why data not appearing in HTML fields when using knockout.js

I am completely fresher in knockout.js and just started . I just created a simple page in asp.net form application . and put following scripts and HTML .

when i run this code fields are still showing blank

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="Scripts/knockout-1.2.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        var product = { itemNumber: "T314CE", model: "Taylor 314ce", salePrice: 1199.95 };
        ko.applyBindings(product);
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2>
            With Knockout</h2>
        <span>Item number</span><span data-bind="text: itemNumber"></span>
        <br />
        <span>Guitar model:</span><input data-bind="value: model" />
        <span>Sales price:</span><input data-bind="value: salePrice" />
    </div>
    </form>
</body>
</html>

no js error ? How can i find the reason behind this ?

您应该在document.ready上调用该函数,或者您可以将脚本块放在HTML文档的底部。

rahularyansharma你的绑定在你的DOM加载之前执行..所以它永远不会工作,直到它将在document.ready或页面底部脚本区域内超越。

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