Đang chuẩn bị liên kết để tải về tài liệu:
the book of javascript 2nd edition phần 4
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Ebook này sẽ cung cấp thêm cho các bạn yêu thích lập trình Javar thêm nhiều thông tin lí thú. Sách được chia làm 5 phần rõ ràng gồm: Tổng quan về JavaScript, Sử dụng JavaScript, Hàm và đối tượng, Tạo đối tượng trong JavaScript, Sự kiện trong JavaScript. | 8 KEEPING TRACK OF INFORMATION WITH ARRAYS AND LOOPS The last chapter showed you how JavaScript stores radio buttons and pull-down menu options in lists. In programmer s parlance lists are called arrays. This chapter will teach you how to create your own arrays and use them to keep track of large amounts of information. In this chapter you ll learn how to Use JavaScript s built-in arrays to control your HTML Create new arrays of your own information Use loops to search through arrays for information Real-World Examples of Arrays JavaScript s built-in arrays are useful in a wide variety of applications. One of the sites I work on http www.antweb.org uses JavaScript s built-in arrays to show users which species of ants live in various counties in the San Francisco Bay Area see Figure 8-1 . At the bottom of the list of counties is a Select All checkbox. Clicking this box causes all the other checkboxes to become checked. This trick is easy to script because the checkboxes are stored in an array allowing me to use JavaScript to check off each one. Browse to http www.bookofjavascript.com Websites AntWeb to see this in action. Figure 8-1 AntWeb checkboxes Creating your own arrays can be useful as well. The Book of JavaScript website employs arrays to show visitors a series ofJavaScript programming tips. In the textarea in Figure 8-2 you ll see one of a dozen programming tips that rotate through this box. I store these tips in a JavaScript array and rotate through the array to put different tips into the textarea. The same principle applies to making a timed slide show which we ll see in the next chapter. Figure 8-2 Rotating programming tips on the Book of JavaScript home page JavaScript s Built-In Arrays When a web browser reads an HTML page it automatically creates a number of arrays. In the previous chapter we saw that JavaScript creates an array for each set of radio buttons with the same name. If you create a set of radio buttons named age inside a form named .