我有一個PHP腳本,它在div(id =「schedule_wrapper_all」)中生成以下HTML。jQuery - Simple「on('click')」選擇器問題
生成的代碼:
<div class="appointments">
<div class="weekday" value="2014-01-08">Wednesday 01/08</div>
<div class="appt" value="2">
<p class="c_name">William Davis</p>
<div class="c_info" style="display: none;">
<p class="c_street">230 N State Rd</p>
<p class="c_city">Davison</p>
<p class="c_time">11:00:00</p>
<p class="c_phone">Phone 1: </p>
<p class="c_phone_alt">Phone 2: </p>
</div>
<div class="c_functions" style="display: none;">
<p><button type="button" class="view_notes">View Notes</button></p>
<p><button type="button" class="add_note">Add Note</button></p>
<p><button type="button" class="reschedule">Reschedule</button></p>
<p><button type="button" class="reassign">Reassign</button></p>
</div>
</div>
<div class="appt" value="4">
<p class="c_name">Mary Smith</p>
<div class="c_info" style="display: none;">
<p class="c_street">123 Main St</p>
<p class="c_city">Davison</p>
<p class="c_time">13:00:00</p>
<p class="c_phone">Phone 1: 8104124200</p>
<p class="c_phone_alt">Phone 2: 8109311416</p>
</div>
<div class="c_functions" style="display: none;">
<p><button type="button" class="view_notes">View Notes</button></p>
<p><button type="button" class="add_note">Add Note</button></p>
<p><button type="button" class="reschedule">Reschedule</button></p>
<p><button type="button" class="reassign">Reassign</button></p>
</div>
</div>
<div class="weekday" value="2014-01-10">Friday 01/10</div>
<div class="appt" value="10">
<p class="c_name">Nancy Poole</p>
<div class="c_info" style="display: none;">
<p class="c_street">111 Main St</p>
<p class="c_city">Ortonville</p>
<p class="c_time">13:30:00</p>
<p class="c_phone">Phone 1: 8101111111</p>
<p class="c_phone_alt">Phone 2: 8109999999</p>
</div>
<div class="c_functions" style="display: none;">
<p><button type="button" class="view_notes">View Notes</button></p>
<p><button type="button" class="add_note">Add Note</button></p>
<p><button type="button" class="reschedule">Reschedule</button></p>
<p><button type="button" class="reassign">Reassign</button></p>
</div>
</div>
</div>
有多種 '預約',每個 'APPT' DIV內的幾個按鈕。我試圖從選定的'appt'div中選擇按鈕(class =「view_notes」)。這裏是jQuery代碼我已經寫:
$(document).ready(function() {
$('#this_week').on('click', function() {
$.ajax({
method: 'post',
url: 'scripts/get_schedule_thisWeek.php',
success: function(data) {
$('#schedule_wrapper_all').html(data);
$('.c_info').hide();
$('.c_functions').hide();
}
});//end ajax - Fill appointments this week
});
$('#schedule_wrapper_all').on('click', '.appt', function() {
$('html,body').animate({
scrollTop: $(this).offset().top},
'slow');//end force to top
$('.c_info', this).slideToggle();
$('.c_functions', this).slideToggle();
}); //Slide Toggle appointment information
=============================PROBLEMATIC AREA================================
$('.appointments').on('click', '.view_notes', function(e) {
e.stopImmediatePropagation(); //Stops the slide toggle from the .item class
alert('hello');
});//Open Modal to view notes
});
正如你所看到的,一旦用戶選擇了「聘任」的div,但它確實一個滑動開關,顯示出兩個的div(c_info和c_functions)的更多信息。我需要用戶能夠選擇按鈕(class =「view_notes」)。我似乎無法得到正確的選擇器。我標記了我遇到的問題。目前,一個簡單的「警報」就足夠了。
在此先感謝您的幫助。
你的第二個建議奏效了。我很感激! –
'e.preventDefault()'優於返回false,主要是因爲它不是'返回'。 – qooplmao