1

我正在尝试访问在其类中有句点的 div clazz.id,但返回的长度为 0

我做了以下 jsFiddle 来说明我的问题

jsFiddle

这是我的html

<div id="activity-operation" style="" class="edit-form">
    <form class="form1">
        <div class="server-error" style="display: none;"></div>
        <fieldset>
            <div>
                <input id="c49_id" name="id" type="hidden" class="myClassCustom" value="1">
            </div>
            <div>
                <input id="c49_subject_id" name="subject_id" type="hidden" class="myClassCustom" value="37">
            </div>
            <div>
                <input id="c49_activityValidationType" name="activityValidationType" type="hidden" value="">
            </div>
            <div class="input swField-name">
                <div class="inputtext">
                    <label for="c49_name" style="float:right;">Activity Name</label>
                </div>
                <div class="inputcontent">
                    <input id="c49_name" name="name" readonly="readonly" disabled="disabled" type="text">
                </div>
                <div class="input-error" style="display:none;"></div>
            </div>
            <div class="input swField-subject.name">
                <div class="inputtext">
                    <label for="c49_subject_name" style="float:right;">Subject</label>
                </div>
                <div class="inputcontent">
                    <input id="c49_subject_name" name="subject_name" readonly="readonly" disabled="disabled" type="text">
                </div>
                <div class="input-error" style="display:none;"></div>
            </div>
            <div class="input swField-activityType.id">
                <div class="inputtext">
                    <label for="c49_activityType_id" style="float:right;">Select Type</label>
                </div>
                <div class="inputcontent">
                    <select id="c49_activityType_id" name="activityType_id">
                        <option value="ASIG">Assignment</option>
                        <option value="CLAS">Class</option>
                        <option value="QUIZ">Quiz</option>
                    </select>
                </div>
                <div class="input-error" style="display:none;"></div>
            </div>
            <div class="input swField-term.id">
                <div class="inputtext">
                    <label for="c49_term_id" style="float:right;">Select Term</label>
                </div>
                <div class="inputcontent">
                    <select id="c49_term_id" name="term_id">
                        <option value="FA12">Fall 2012</option>
                        <option value="FA13">Fall 2013</option>
                        <option value="SP12">Spring 2012</option>
                        <option value="SP13">Spring 2013</option>
                    </select>
                </div>
                <div class="input-error" style="display:none;"></div>
            </div>
            <div class="input swField-grading">
                <div class="inputtext">
                    <label for="c49_grading" style="float:right;">Grading</label>
                </div>
                <div class="inputcontent">
                    <input id="c49_grading" name="grading" type="text">
                </div>
                <div class="input-error" style="display:none;"></div>
            </div>
            <div class="input swField-class.id error">
                <div class="inputtext">
                    <label for="c49_clazz_id" style="float:right;">Select Class</label>
                </div>
                <div class="inputcontent">
                    <select id="c49_clazz_id" name="clazz_id">
                        <option value="">Select</option>
                        <option value="22">10</option>
                        <option value="10">9b</option>
                        <option value="11">9c</option>
                        <option value="40">A</option>
                        <option value="41">B</option>
                        <option value="24">c1</option>
                        <option value="25">c2</option>
                        <option value="26">c3</option>
                        <option value="27">c4</option>
                        <option value="87">Obj 1</option>
                        <option value="86">Rawalpindi Board</option>
                    </select>
                </div>
                <div class="input-error" style="display:none;">Class is required</div>
            </div>
            <div class="input swField-section.id">
                <div class="inputtext">
                    <label for="c49_section_id" style="float:right;">Select Section</label>
                </div>
                <div class="inputcontent">
                    <select id="c49_section_id" name="section_id" readonly="readonly" disabled="disabled">
                        <option value="select"></option>
                    </select>
                </div>
                <div class="input-error" style="display:none;"></div>
            </div>
            <div class="input swField-description">
                <div class="inputtext">
                    <label for="c49_description" style="float:right;">Description</label>
                </div>
                <div class="inputcontent">
                    <textarea id="c49_description" name="description" type="text"></textarea>
                </div>
                <div class="input-error" style="display:none;"></div>
            </div>
        </fieldset>
        <div class="buttons">
            <input class="orangebutton swFormSubmitButton" type="submit" value="Submit">
            <input class="greybutton swFormCancelButton" type="submit" value="Cancel">
        </div>
    </form>
</div>

这些是我正在尝试的选择器

alert($("form.form1").find(".swField-clazz\\\\.id div.inputcontent").length);

alert($("form.form1").find(".swField-clazz\\.id div.inputcontent").length);

我试图\\ 逃避课堂上的那段时间,但它似乎不起作用

4

2 回答 2

3

逃避\\实际上有效。

swField-clazz.id在您的 HTML中根本没有这样的类。

不过,请尝试去掉班级名称中的句点。

于 2013-04-18T16:03:19.203 回答
2

这工作正常: alert($("form.form1").find(".swField-activityType\\.id div.inputcontent").length);

请参阅更新的小提琴:http: //jsfiddle.net/WrdXB/1/

于 2013-04-18T16:12:28.167 回答