TAILIEUCHUNG - build your own ajax web applications PHẦN 6

Tiếp theo, có một vòng lặp trong khi, mà đảm bảo rằng chúng ta đang quay trở lại các yếu tố chúng ta mong đợi. Mặc dù thực tế mà chúng tôi đã gắn liền với xử lý sự kiện cho div chính của nhập, tài sản srcElement hoặc mục tiêu sẽ chứa một tham chiếu đến các yếu tố thực tế mà người sử dụng nhấp vào. | Getting the Entry s ID Next there s a while loop which ensures that we re returning the element we expect. Despite the fact that we ve attached the event handler to the entry s main div the srcElement or target property will contain a reference to the actual element on which the user clicked. For example consider the following markup. If the user clicks on the text in the paragraph the p element will be returned not the mainl div you might have expected. div id main1 div id title1 class entryTitle Stargate SG-1 div div id body1 class entryBody p Is that actually sci-fi Or just a bunch of guys in Army uniforms p div div To get around this behavior we inspect the innermost element to see if it has an id attribute. If it doesn t we check its parent and if its parent doesn t we check its parent and so on. The first element we find with an id attribute should be the main title or body div any of which will be just fine for our purposes in toggleEditInPlace. Getting the Entry s ID Now that we have one of the entry s divs in toggleEditInPlace we use the id of the returned element to work out the ID of the entry to edit File excerpt elem e id main title body This code pulls out the ID of the entry from the id of the div. To do so the code uses replace to strip the main title or body prefix from the ID of the div element which leaves us with the entry s ID. This technique of using event listeners and taking specific actions according to the ID of the clicked interface element is a very powerful one. We ll expand on it further a little later in the book. 139 Licensed to siowchen@ Chapter 5 Broader AJAX with Edit-in-place Changing the State The last chunk of toggleEditInPlace is the part that actually turns the editable state on and off. The code looks like this File excerpt if id editCancel id false else if id editCancel if

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.