The KNOCKOUTJS environment constructs the course _javascript the skill

Source: Internet
Author: User
Recently to use Knockoutjs in the project, so today I first studied the KNOCKOUTJS environment, and conducted a simple test.
First to http://knockoutjs.com/index.html download the latest version of the Knockoutjs, the author here to download is knockout-2.2.0.js. Then create a new. html file and add the following statement to the HTML document to import this JS:
<script type= "Text/javascript" src= "Knockout-2.2.0.js" ></script>
Here we are ready to write Knockoutjs code, we print "Hello world!!" For example, write the following code:
Copy Code code as follows:

<script type= "Text/javascript" src= "Knockout-2.2.0.js" ></script>
<span data-bind= "Text:helloworld" ></span>
<script type= "Text/javascript" >
var Appviewmodel = {
HelloWorld: ' Hello world!! '
};
Ko.applybindings (Appviewmodel);
</script>

Then use the browser to open this HTML file, you can see "Hello world!!" The words.
In the above code:
<span data-bind= "Text:helloworld" ></span>
Defines a span and uses Data-bind to bind the HelloWorld to a span so that the contents of the span are the contents of the HelloWorld variable.
Copy Code code as follows:

<script type= "Text/javascript" >
var Appviewmodel = {
HelloWorld: ' Hello world!! '
};
Ko.applybindings (Appviewmodel);
</script>

A appviewmodel is defined in the script, and a variable is defined for it: HelloWorld, its value is: Hello world!!, and then using the Ko.applybindings () method to activate Appviewmodel, This allows you to see this content in the Web page.
The above is just using Knockoutjs to do a very simple example, in the process of running this example, there is a small problem, I do not know why. The code previously written is:
Copy Code code as follows:

<script type= "Text/javascript" src= "Knockout-2.2.0.js" ></script>
<script type= "Text/javascript" >
var Appviewmodel = {
HelloWorld: ' Hello world!! '
};
Ko.applybindings (Appviewmodel);
</script>
<span data-bind= "Text:helloworld" ></span>

I put <script> in front of <span>, so that will not show any content, not very clear the reasons, but also please advise.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.