Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > Windows Store Apps > Windows Store and Basic > JavaScript ทดสอบสร้าง Project ของ Windows Store Apps ด้วย JavaScript



Clound SSD Virtual Server

JavaScript ทดสอบสร้าง Project ของ Windows Store Apps ด้วย JavaScript

JavaScript ทดสอบสร้าง Project ของ Windows Store Apps ด้วย JavaScript สำหรับภาษา Java Script นับได้ว่าเป็นทางเลือกใหม่สำหรับการเขียน Apps บน Windows Store โดยอาศัยภาษา HTML เป็น Interface เหมือนกับการเขียนเว็บทั่ว ๆ ไป แต่จะอาศัยการใช้ Tags ของ HTML5 และเขียนถูกต้องตามหลักของ CSS โดยการทำงานต่าง ๆ เราจะใช้ JavaScript เป็นตัวควบคุมอีกครั้ง ซึ่ง JavaScript ที่ใช้จะไม่ใช่ภาษา JavaScript ทั่ว ๆ ไปที่เราสามารถเขียนพวกคำสั่ง alert() ได้ทันที แต่ยังคงใช้ Framework ในรูปแบบของภาษา JavaScript ที่ Windows Store Apps ได้ออกแบบมาให้โดยเฉพาะ ซึ่งจะทำงานประสานไปยัง API ที่ถูกออกแบบไว้อีกชั้นหนึ่ง

    <link href="//Microsoft.WinJS.2.0/css/ui-dark.css" rel="stylesheet" />
    <script src="//Microsoft.WinJS.2.0/js/base.js"></script>
    <script src="//Microsoft.WinJS.2.0/js/ui.js"></script>

ในหน้า HTML จะมีการเรียกใช้ JavaScript Library ต่าง ๆ ในการทำงานร่วมกับ API ของ WinRT ที่ควบคุม Application ของ Windows Store Apps แต่พวกคำสั่งพื้นฐานทั่ว ๆ ไปยังสามารถใช้ Syntax ของภาษา JavaScript ได้ตามปกติ เช่น

                var userName = document.getElementById("nameInput").value;
                var greetingString = "Hello, " + userName + "!";
                document.getElementById("greetingOutput").innerText = greetingString;

Windows Store Apps  C#

Windows Store Apps ด้วย JavaScript


เรามาลองดูวิธีการสร้าง Project ของ Windows Store Apps ด้วยภาษา JavaScript และ HTML แบบง่าย ๆ

Windows Store Apps  JavaScript

เปิดโปรแกรม Visual Studio เลือก FILE -> New Project....

Windows Store Apps  JavaScript

เลือก JavaScript -> Windows Store

Windows Store Apps  JavaScript

เราจะได้โครงสร้างของ Project ดังรูป ซึ่งไฟล์ที่เราจะให้ความสนใจก็คือ default.html ซึ่งเป็นไฟล์แรกของ Apps ที่จะทำงานเมื่อมีการ Run โปรแกรม

Windows Store Apps  JavaScript

เมื่อคลิกเข้าไปใน default.html จะเห็นว่าเป็นรูปแบบของ JavaScript และ HTML5 ที่เราคุ้นเคย เหมือนกับการเขียนเว็บทั่ว ๆ ไป

Windows Store Apps  JavaScript

ทดสอบการสร้าง Page ง่าย ๆ ดังรูป

    <h1>Hello, world!</h1>
    <p>What's your name?</p>
    <input id="nameInput" type="text" />
    <button id="helloButton">Say "Hello"</button>
    <div id="greetingOutput"></div>









default.html
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>AppsJavaScript</title>

    <!-- WinJS references -->
    <link href="//Microsoft.WinJS.2.0/css/ui-dark.css" rel="stylesheet" />
    <script src="//Microsoft.WinJS.2.0/js/base.js"></script>
    <script src="//Microsoft.WinJS.2.0/js/ui.js"></script>

    <!-- AppsJavaScript references -->
    <link href="/css/default.css" rel="stylesheet" />
    <script src="/js/default.js"></script>

    <script type="text/javascript">

        (function () {
            "use strict";

            var app = WinJS.Application;
            var activation = Windows.ApplicationModel.Activation;

            app.onactivated = function (args) {
                if (args.detail.kind === activation.ActivationKind.launch) {
                    if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
                        // TODO: This application has been newly launched. Initialize
                        // your application here.
                    } else {
                        // TODO: This application has been reactivated from suspension.
                        // Restore application state here.
                    }
                    args.setPromise(WinJS.UI.processAll());

                    // Retrieve the button and register our event handler. 
                    var helloButton = document.getElementById("helloButton");
                    helloButton.addEventListener("click", buttonClickHandler, false);
                }
            };

            app.oncheckpoint = function (args) {
                // TODO: This application is about to be suspended. Save any state
                // that needs to persist across suspensions here. You might use the
                // WinJS.Application.sessionState object, which is automatically
                // saved and restored across suspension. If you need to complete an
                // asynchronous operation before your application is suspended, call
                // args.setPromise().
            };

            function buttonClickHandler(eventInfo) {

                var userName = document.getElementById("nameInput").value;
                var greetingString = "Hello, " + userName + "!";
                document.getElementById("greetingOutput").innerText = greetingString;
            }

            app.start();
        })();

    </script>
</head>
<body>
    <h1>Hello, world!</h1>
    <p>What's your name?</p>
    <input id="nameInput" type="text" />
    <button id="helloButton">Say "Hello"</button>
    <div id="greetingOutput"></div>
</body>
</html>


Windows Store Apps  JavaScript

ทดสอบการทำงาน แสดงผลบน Simulator

Windows Store Apps  JavaScript

ทดสอบการทำงาน Input ข้อมูล

Windows Store Apps  JavaScript

โปรแกรมจะแสดงโต้ตอบดังภาพ

จากตัวอย่างนี้เราจะเห็นว่า Code ค่อนข้างจะเยอะพอสมควร แต่รูปแบบการเขียนนี้เป็น Framework ที่ถูกออแบบมาเพื่อให้ JavaScript สามารถทำงานร่วมกับ API ของ WinRT ที่จะสั่งให้ Windows Store Apps ทำงานต่าง ๆ ได้ ซึ่งเราอาจจะใช้การเรียนรู้และปรับตัวให้เข้ากับ Framework บางพอสมควร







.

   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2014-02-01 14:46:12 / 2017-03-19 14:36:33
  Download : No files
 Sponsored Links / Related

 
วิธีสร้างโปรเจค Windows Store App ใช้งานบน Windows Store รันบน Windows 8
Rating :

 
ภาษาต่าง ๆ บน Visual Studio ไว้สำหรับพัฒนา Apps บน Windows Store Apps
Rating :

 
C# และทดสอบสร้าง Project ของ Windows Store Apps ด้วย C#
Rating :

 
VB.Net และทดสอบสร้าง Project ของ Windows Store Apps ด้วย VB.Net
Rating :

 
C++ และทดสอบสร้าง Project ของ Windows Store Apps ด้วย C++
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่