使用jquery load()加载外部表单后提交不起作用

时间:2017-12-31 14:24:46

标签: jquery

我有一个问题:

当我在当前页面上加载外部表单时,jQuery .submit()无法正常工作。 请参阅以下代码:

HTML

<div class="right-section job-desc col-md-12">
    <img id="cover_letter_edit" alt="" src="http://localhost/cv3/frontend_assets/images/icons/edit.png" class="float-right edit-icon">
    <h3>Cover Letter & Resume</h3>
    <div class="clearfix"></div>
    <div id="cover_letter_view_sec">
        <p>What is the job about? Enter overall description of your job.What is the job about? Enter overall description of
            your job.What is the job about? Enter overall description of your job.What is the job about? Enter overall description
            of your job.What is the job about? Enter overall description of your job.What is the job about? Enter overall
            description of your job.</p>
    </div>
    <div id="load_edit_cover"></div>
</div>

的jQuery

$(document).ready(function () {
    //alert(2)
    $("#cover_letter_edit").click(function () {
        $("#cover_letter_view_sec").hide();
        $("#load_edit_cover").load(getBaseURL() + '/home/editCoverLetter')
    })
    $("#cover_letter_edit_sec").submit(function (e) {
        e.preventDefault();
        alert(1)
    })
})

已加载的表单内容:

$attribute = array("id" => "cover_letter_edit_sec", "class" => "form-horizontal", "method" => "post");
echo form_open('', $attribute) ?>

<div class="form-group">
<label class="col-md-3">Cover Letter</label>
    <textarea rows="5" cols="50" name="" value="" id="" class="form-control col-md-8"></textarea>
</div>
<div class="form-group">
<label class="col-md-3">Upload Resume</label>
    <input type="file" name="resume" value="" id="" class="form-control col-md-8">
</div>
<div class="form-group">
    <label class="col-md-3"></label>
    <button type="submit" class="btn btn-primary">Save</button>
    <button type="submit" class="btn btn-warning cancleButton">Cancle</button>
</div>

当我提交表单时,此代码无效:

$("#cover_letter_edit_sec").submit(function (e) {
    e.preventDefault();
    alert(1)
})

请检查代码。

由于

0 个答案:

没有答案