jQuery-Simple";在(';单击';)上“;选择器问题

jQuery-Simple";在(';单击';)上“;选择器问题,jquery,Jquery,我有一个PHP脚本,它在div(id=“schedule\u wrapper\u all”)中生成以下HTML 生成的代码: <div class="appointments"> <div class="weekday" value="2014-01-08">Wednesday 01/08</div> <div class="appt" value="

我有一个PHP脚本,它在div(id=“schedule\u wrapper\u all”)中生成以下HTML

生成的代码:

<div class="appointments">
    <div class="weekday" value="2014-01-08">Wednesday 01/08</div>
    <div class="appt" value="2">
        <p class="c_name"></p>
        <div class="c_info" style="display: none;">
            <p class="c_street"></p>
            <p class="c_city"></p>
            <p class="c_time"></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"></p>
            <p class="c_city"></p>
            <p class="c_time"></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="weekday" value="2014-01-10">Friday 01/10</div>
    <div class="appt" value="10">
        <p class="c_name">Nancy </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,它就会进行滑动切换,在另外两个div(c_info和c_函数)中显示更多信息。我需要用户能够选择按钮(class=“查看注释”)。我好像找不到正确的选择器。我标记了我遇到问题的区域。现在,一个简单的“警报”就足够了

提前感谢您的帮助。

试试这个

$(".appointments .view_notes").on('click', function(e) {
        e.stopImmediatePropagation(); //Stops the slide toggle from the .item class
        alert('hello');
    });//Open Modal to view notes
如果有必要,你甚至可以更严格一点,如果你想确保它只影响c_函数中的视图注释,就像这样

$(".appointments .c_functions>.view_notes").on('click', function(e) {
        e.stopImmediatePropagation(); //Stops the slide toggle from the .item class
        alert('hello');
    });//Open Modal to view notes
我假设PHP没有通过AJAX加载内容,因为您提到PHP正在创建页面。如果是,那么您可能需要直到内容加载成功,然后再进行绑定,因为DOM元素可能仍然不存在。

试试这个

$(".appointments .view_notes").on('click', function(e) {
        e.stopImmediatePropagation(); //Stops the slide toggle from the .item class
        alert('hello');
    });//Open Modal to view notes
如果有必要,你甚至可以更严格一点,如果你想确保它只影响c_函数中的视图注释,就像这样

$(".appointments .c_functions>.view_notes").on('click', function(e) {
        e.stopImmediatePropagation(); //Stops the slide toggle from the .item class
        alert('hello');
    });//Open Modal to view notes
我假设PHP没有通过AJAX加载内容,因为您提到PHP正在创建页面。如果是,那么您可能需要直到内容加载成功,然后再进行绑定,因为DOM元素可能仍然不存在。

试试这个

$(".appointments .view_notes").on('click', function(e) {
        e.stopImmediatePropagation(); //Stops the slide toggle from the .item class
        alert('hello');
    });//Open Modal to view notes
如果有必要,你甚至可以更严格一点,如果你想确保它只影响c_函数中的视图注释,就像这样

$(".appointments .c_functions>.view_notes").on('click', function(e) {
        e.stopImmediatePropagation(); //Stops the slide toggle from the .item class
        alert('hello');
    });//Open Modal to view notes
我假设PHP没有通过AJAX加载内容,因为您提到PHP正在创建页面。如果是,那么您可能需要直到内容加载成功,然后再进行绑定,因为DOM元素可能仍然不存在。

试试这个

$(".appointments .view_notes").on('click', function(e) {
        e.stopImmediatePropagation(); //Stops the slide toggle from the .item class
        alert('hello');
    });//Open Modal to view notes
如果有必要,你甚至可以更严格一点,如果你想确保它只影响c_函数中的视图注释,就像这样

$(".appointments .c_functions>.view_notes").on('click', function(e) {
        e.stopImmediatePropagation(); //Stops the slide toggle from the .item class
        alert('hello');
    });//Open Modal to view notes

我假设PHP没有通过AJAX加载内容,因为您提到PHP正在创建页面。如果是,那么您可能需要直到内容加载成功,然后再进行绑定,因为DOM元素可能仍然不存在。

问题是,
约会
元素也是动态加载的,因此您需要将单击处理程序绑定到
计划包装器\u all
元素

$('#schedule_wrapper_all').on('click', '.view_notes', function (e) {
    e.stopPropagation(); //Stops the slide toggle from the .item class
    alert('hello');
}); //Open Modal to view notes

问题是
appointments
元素也是动态加载的,因此需要将click处理程序绑定到
schedule\u wrapper\u all
元素

$('#schedule_wrapper_all').on('click', '.view_notes', function (e) {
    e.stopPropagation(); //Stops the slide toggle from the .item class
    alert('hello');
}); //Open Modal to view notes

问题是
appointments
元素也是动态加载的,因此需要将click处理程序绑定到
schedule\u wrapper\u all
元素

$('#schedule_wrapper_all').on('click', '.view_notes', function (e) {
    e.stopPropagation(); //Stops the slide toggle from the .item class
    alert('hello');
}); //Open Modal to view notes

问题是
appointments
元素也是动态加载的,因此需要将click处理程序绑定到
schedule\u wrapper\u all
元素

$('#schedule_wrapper_all').on('click', '.view_notes', function (e) {
    e.stopPropagation(); //Stops the slide toggle from the .item class
    alert('hello');
}); //Open Modal to view notes

可能父节点还不存在。如果是这样的话,这应该是可行的:

$(document).on('click', '.appointments .view_notes', function(e) {        
    alert('hello');
    return false; //Also cancels default behavior
});
如果上述方法有效,您可以改进选择器(更干净、更高效):


希望这有帮助。干杯

可能父节点还不存在。如果是这样的话,这应该是可行的:

$(document).on('click', '.appointments .view_notes', function(e) {        
    alert('hello');
    return false; //Also cancels default behavior
});
如果上述方法有效,您可以改进选择器(更干净、更高效):


希望这有帮助。干杯

可能父节点还不存在。如果是这样的话,这应该是可行的:

$(document).on('click', '.appointments .view_notes', function(e) {        
    alert('hello');
    return false; //Also cancels default behavior
});
如果上述方法有效,您可以改进选择器(更干净、更高效):


希望这有帮助。干杯

可能父节点还不存在。如果是这样的话,这应该是可行的:

$(document).on('click', '.appointments .view_notes', function(e) {        
    alert('hello');
    return false; //Also cancels default behavior
});
如果上述方法有效,您可以改进选择器(更干净、更高效):



希望这有帮助。干杯

不知道你为什么被否决。我在发帖前试过这个,但没用。谢谢你的建议。我不知道你为什么被否决。我在发帖前试过这个,但没用。谢谢你的建议。我不知道你为什么被否决。我在发帖前试过这个,但没用。谢谢你的建议。我不知道你为什么被否决。我在发帖前试过这个,但没用。不过谢谢你的建议。内容是通过AJAX生成的。我可能应该更仔细地措辞。jQuery文件中的第一个函数是填充PHP的函数。如果需要的话,我可以显示PHP源代码。尝试将绑定放在SuccessBug中。我通常会在firebug中的绑定行上放置一个断点。当我运行页面时,我的断点被击中,我检查elements视图,看看DOM是否存在。如果没有,那么你的第一条评论对我来说真的很清楚,因为我对网络开发还是新手。我记得我读过一篇文章,在选择DOM元素之前,它必须存在,而AJAX将动态生成div,因此它当时不可选择。谢谢你在我的脑海里凝固了它;)内容是通过AJAX生成的。我可能应该更仔细地措辞。jQuery文件中的第一个函数是填充PHP的函数。如果需要的话,我可以显示PHP源代码。尝试将绑定放在SuccessBug中。我通常会在firebug中的绑定行上放置一个断点。当我运行页面时,我的断点被击中,我检查elements视图,看看DOM是否存在。如果没有,那么你的第一条评论对我来说真的很清楚,因为我对网络开发还是新手。我记得我读过一篇文章,在选择DOM元素之前,它必须存在,而AJAX将动态生成div,因此它当时不可选择。谢谢你在我的脑海里凝固了它;)内容是通过AJAX生成的。我可能应该更仔细地措辞。jQuery文件中的第一个函数是填充PHP的函数。如果需要的话,我可以显示PHP源代码。试着将绑定放在success中。我通常做的是在fir中放置一个断点