0

私はこれととても混乱しています。jquery 1.9.1 を使用して、div の内部 html を別の div に追加しています。しかし、クロム開発者ツールでデバッグしようとすると、jquery ライブラリ内でこのエラーが発生しました。

私のHTML:

<body>
    <s:form action="/save" method="POST">
        <div class="educationForm">
            <div class="educations">
                <label>Position</label>
                <input type="text" name="educations[0].index" value="1" />
                <br/>
                <label>School</label>
                <input type="text" name="educations[0].school" />
                <br/>
                <label>Degree</label>
                <input type="text" name="educations[0].degree" />
                <br/>
                <label>GPA</label>
                <input type="text" name="educations[0].scored" />
                <br/>
                <label>Start Date</label>
                <input type="text" name="educations[0].startDate" />
                <br/>
                <label>End Date</label>
                <input type="text" name="educations[0].endDate" />
                <br/>
            </div>
        </div>  <a href="#" id="addButton">Add new Edu</a>

        <input type="submit" value="Save" />
    </s:form>
    <div class="template_educations" style="display:none">
        <div class="educations">
            <label>Position</label>
            <input type="text" name="educations[_X_].index" />
            <br/>
            <label>School</label>
            <input type="text" name="educations[_X_].school" />
            <br/>
            <label>Degree</label>
            <input type="text" name="educations[_X_].degree" />
            <br/>
            <label>GPA</label>
            <input type="text" name="educations[_X_].scored" />
            <br/>
            <label>Start Date</label>
            <input type="text" name="educations[_X_].startDate" />
            <br/>
            <label>End Date</label>
            <input type="text" name="educations[_X_].endDate" />
            <br/>
        </div>
    </div>
</body>

私のjs:

$(document).ready(function(){
    $("#addButton").click(function(event){
        event.preventDefault();
        $(".educationForm").append($(".template_educations").html);
        $(".educationForm").children(".educations").last().children("input").each(function(){           
            var count = $(".educationForm").children(".education").length();
            var value = $(this).attr("name");
            value.replace("_X_", count + 1);
            $(this).attr("name", value);
        });         
    });
});

emptyコード内で関数を使用していないため、これがjqueryライブラリのバグなのか、コードに問題があるのか​​ を判断するのを手伝ってください

4

2 に答える 2

5

html()..代わりにhtml..であるべきです

....
$(".educationForm").append($(".template_educations").html());
....                                                 //--^^---here
于 2013-04-03T06:20:25.517 に答える
2

この行を使用してください

 $(".educationForm").append($(".template_educations").html);

など

    $(".educationForm").append($(".template_educations").html());
于 2013-04-03T06:24:05.820 に答える