To add JavaScript Windows Library controls to our app, let's start by adding a scoring control in the previous demo
Unlike HTML controls, Windows Library controls for JavaScript do not have a dedicated markup element: for example, you cannot create rating controls by adding <rating/> elements. To add a Windows library control for JavaScript, you can create a DIV element and use the Data-win-control property to specify the type of control you want. To add a Rating control, set the property to "WinJS.UI.Rating".
The above code is our previous demo, unfamiliar to see the previous example
Operation Result:
Nothing happens when we manipulate the scoring control, and then we register the event with it
Open the Default.js file, add the following snippet, rating control has a Change event we register this event
1 function ratingchanged (eveninfo) 2 {3 var ratingoutput = document.getElementById ("Ratingoutput"); 4 Ratingoutput.innertext = "You have made a" +eveninfo.detail.tentativerating+ "evaluation of the Answer"; 5 }
How do you call this method?
1 app.onactivated = function (args) {2 if (args.detail.kind = = = Activation. Activationkind.launch) {3 if (args.detail.previousExecutionState!== activation. applicationexecutionstate.terminated) {4//TODO: This application just started. Initialize 5//your application here. 6} else {7//TODO: This application has been reactivated from the suspended state. 8//Restore application state here. 9}//The Change event for the rating control is registered here
Args.setpromise (WinJS.UI.processAll () then (function completed () {one-by-one var ratingcontroldiv = document.getElementById ("Ratingcontroldiv"); var Ratingcontrol = ratingcontroldiv.wincontrol;13 Ratingcontrol.addeventlistener ("Change", ratingchanged, False)); var Hellobutto n = document.getElementById ("Btnhello"); hellobutton.classname = "ButtonStyle"; hellobutton.ad Deventlistener ("Click", Buttonclickhandler, false); 19}20};
The results of the operation are as follows:
This is the first WIN8 application written in Html+javascript, referring to examples provided by Microsoft
This article is from the blog of Small Hui only, the original address: http://www.cnblogs.com/zhaohuionly/archive/2012/11/26/2788609.html
Create a WIN8 application using javascript+html (ii)