JavaScript in 10 Simple Steps or Less 2007 phần 3

Logic của các mã trong nhiệm vụ này rất đơn giản: Chia chuỗi các dấu hỏi, lấy một phần bên phải của dấu chấm hỏi và chia nó ở mỗi ký hiệu, và sau đó đi mỗi chuỗi kết quả và phân chia chúng tại bằng dấu hiệu để phân chia các tham số URL giữa tên của họ và các bộ phận giá trị. | 106 Part 2 Task Customizing Output Using URL Variables When you build a URL for a page you can add a series of name-value pairs to the end of the URL in the following form note The logic of the code in this task is simple Split the string at the question mark take the part to the right of the question mark and split it at each ampersand and then take each of the resulting substrings and split them at the equal sign to split the URL parameters between their name and value parts. Using the split method of the string object helps make this process easy. caution The code in this task will only work properly if there is at least one URL parameter passed to the script. When doing this keep a couple points in mind First you must access the file through a Web server and not open it as a local file and second you must include at least one namevalue pair after the question mark in the URL. http name1 value1 .name2 value2 . Essentially these parameters are like variables named containers for values. In JavaScript the document object provides the URL property that contains the entire URL for your document and using some manipulation on this property you can extract some or all of the URL parameters contained in the URL. The following code displays all URL parameters for the current document 1. In a script block in the body of a document separate the current document s URL at the question mark and store the two parts in the array urlParts var urlParts 2. Split the part of the URL to the right of the question mark into one or more parts at the ampersand. This places each name-value pair into an array entry in the parameterParts array. var parameterparts urlParts 1 .split 3. Output the HTML code to set up a table and display column headers for the table using the method table border 1 cellpadding 3 cellspacing 0 tr td strong Name strong td td strong Value strong td 4. Start a for .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
7    307    3    30-04-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.