- Mastering jQuery UI
- Vijay Joshi
- 537字
- 2021-07-23 20:33:34
Creating the layout
In the newly created folder Chapter1
, create a file named index.html
and another .js
file named quiz.js
inside the js
folder of Chapter1
. The quiz.js
file will contain all the code that we need to make the quiz functional.
Markup for the quiz page
Open the index.html
file for editing using your favorite text editor, and write the following code in it:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Designing a simple quiz application</title> <link rel="stylesheet" href="css/ui-lightness/jquery-ui-1.10.4.custom.min.css"> </head> <body> <div class="container"> <span id="score"></span> <button id="reset" type="button">Reset</button> <div class="clear"></div> <hr/> <div id="leftCol"> <ul id="source"> </ul> </div> <div id="rightCol"> <ul id="target"> </ul> </div> </div> <div id="dialog-complete" title="Well Done!"> <p><span class="ui-icon ui-icon-check"></span> Well done. You have completed the quiz successfully.</p> </div> <script src="js/jquery-1.10.2.js"></script> <script src="js/jquery-ui-1.10.4.custom.min.js"></script> <script src="js/quiz.js"></script> </body> </html>
Tip
Downloading the example code
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
In the preceding code, inside the head
section, we referenced the jQuery UI .css
file. If you have placed the .css
file elsewhere, make sure to correct the path accordingly. The path can either be an absolute path or a relative path.
Inside the body, we have a div
element named container
that wraps our entire markup. Inside container
, we have created two span
elements. The first span
has the id
value score
and it will be used to show the score of the user. The second span
has the id
value reset
and it will be used to reset the quiz to its initial state.
After this, we have to create two more div
elements having the id
value leftCol
and rightCol
, respectively. leftCol
has an ul
element with the id
value source
inside it. This ul
element will contain the names of countries as list items. Similarly, rightCol
has another ul
element with the id
value target
inside it. It will have the names of capitals as list items.
After the container
element, we have created yet another div
element with the id
value dialog-complete
, which will be displayed once the user has completed the quiz successfully. Inside the dialog-complete
element, we have placed a success message.
Finally, at the bottom of the page, reference the jQuery, jQuery UI, and quiz.js
files.
Styling elements
We will also need some CSS styling to make the elements look good. In the head
section of the index.html
file, write the following code:
<style type="text/css"> body{ font-family:arial,verdana; font-size:12px; margin: 0px auto; width: 600px; } div.container{ border: 1px solid #000; float:left; margin:0 auto; padding:10px; width: 100%; } #leftCol{ float:left; } #rightCol{ float:right; } ul{ list-style:none; margin:0; padding:0; width:50%; } li{ border:1px solid #000; font-weight:bold; margin:5px 0; padding:10px 0; text-align:center; width:175px; } #source li{ cursor:move; } #score{ font-weight:bold; float:left; color:#ff0000; } #reset{ color:#ff0000; cursor:pointer; font-weight:bold; text-align:right; text-decoration:underline; float:right; } .clear{ clear:both; } #dialog-complete{ display:none; } #dialog-complete span{ float:left; margin:0 7px 20px 0; } </style>
In the preceding code, first we defined some basic styles for the body
and the container
elements. After that, the styles were defined for the ul
element and its li
items. These styles will display the list items in the form of individual boxes. CSS for the score
and reset
items follow next and finally some basic styling for the dialog elements.
- SpringMVC+MyBatis快速開發與項目實戰
- 神經網絡編程實戰:Java語言實現(原書第2版)
- PhoneGap Mobile Application Development Cookbook
- C++面向對象程序設計習題解答與上機指導(第三版)
- Android開發案例教程與項目實戰(在線實驗+在線自測)
- Java系統化項目開發教程
- 軟件測試綜合技術
- Java Web開發實例大全(基礎卷) (軟件工程師開發大系)
- jQuery技術內幕:深入解析jQuery架構設計與實現原理
- Learning Grunt
- jQuery從入門到精通(微課精編版)
- Learning Cocos2d-JS Game Development
- JavaEE架構與程序設計
- Less Web Development Cookbook
- JavaScript全棧開發