TAILIEUCHUNG - Tương tác giữa PHP và jQuery - part 25

CHAPTER 7 ■ ENHANCING THE USER INTERFACE WITH JQUERY (); // Adds an "active" class to the link $(this).addClass("active"); // Proves the event handler worked by logging the link text ( $(this).text() ); }); }); After saving this code, reload http://localhost/ in your browser and click any of the event titles. Instead of going to the event details on , the title of the event is output in the console. For instance, if you click the New Year's Day event, you will see the following output in the console: New Year's Day Extracting the Query String with Regular Expressions The modal window is. | CHAPTER 7 ENHANCING THE USER INTERFACE WITH JQUERY Adds an active class to the link this .addClass active Proves the event handler worked by logging the link text this .text After saving this code reload http in your browser and click any of the event titles. Instead of going to the event details on the title of the event is output in the console. For instance if you click the New Year s Day event you will see the following output in the console New Year s Day Extracting the Query String with Regular Expressions The modal window is being created to display event information so you ll need some way of knowing which event should be displayed. Without adding any extra markup you can actually pull the event ID right out of the href attribute using regular expressions. To do this you need to extract the query string from the link. If the href attribute value is http localhost event_id 1 the query string is event_id 1. You will extract the query string using two items .replace a native JavaScript function that accepts a string or regular expression pattern to match and a string or pattern that matches should be replaced with. Using the Lazy Approach String-Based Replacement At a glance the obvious solution might seem to be the following var data http localhost And yes this does work producing the output event_id 1 if you assume the original value of string was http localhost event_id 1 . Unfortunately this approach is not flexible enough for example what if the application is moved to another domain name Or what if the file name is changed to Either change breaks the preceding logic and requires an update to the script. Adopting a Better Solution Regular Expressions However there is a better solution regular expressions. Regular expressions are a powerful patternmatching tool available in most modern programming languages. To extract the query string you ll use a .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.