jQuery - 如何定位嵌套元素?

时间:2013-08-29 08:24:53

标签: jquery html nested

我试图用jquery来定位id。不幸的是,它们嵌套在div中,我的jquery不起作用。举个例子,我将如何定位:

id="beds"

<div id="content">
  <div class="page">
    <form>
        <select class="customSelect_beds" id="beds">

的jQuery

$(document).ready(function () {

$('#beds').change(multiply);
$('#baths').change(multiply);
$('#frequency').change(multiply);

function multiply() {
    var beds = parseFloat($('#beds').val()),
        baths = parseFloat($('#baths').val()),
        baselight = 54,
        bedmodlight = (beds * 12),
        bathmodlight = (baths * 6),
        basereg = 54,
        bedmodreg = (beds * 18),
        bathmodreg = (baths * 12),
        basedeep = 72,
        bedmoddeep = (beds * 24),
        bathmoddeep = (baths * 18),
        discount = $('#frequency').val(),
        light_cleaning = Math.ceil((baselight + bedmodlight + bathmodlight) * discount),
        regular_cleaning = Math.ceil((basereg + bedmodreg + bathmodreg) * discount),
        deep_cleaning = Math.ceil((basedeep + bedmoddeep + bathmoddeep) * discount);

    $('#total_light').text((light_cleaning) || "--");
    $('#total_regular').text((regular_cleaning) || "--");
    $('#total_deep').text((deep_cleaning) || "--");
};

}); 我似乎无法在任何地方找到这些信息(虽然我还在寻找)。有什么提示吗?

编辑 - 为空格添加和截断代码。

2 个答案:

答案 0 :(得分:1)

试试这个:

$('#content').find('#beds');

答案 1 :(得分:1)

由于您拥有ID,因此可以使用id-selector

$('#beds')