1

重複の可能性:
jQueryのform.serializeを使用して空のフィールドを除外するにはどうすればよいですか

フィールド「lastname」からの値なしでajaxを使用して、フォーム内のフィールドからすべての値を送信したいのですが、どうすればそれを行うことができますか? 私のコード:

<script>
    $(document).ready(function () {
        $('#other').click(function () {
            $.post("/Home/About", $("#target").serialize());
        });
    });
</script>

<form id="target" action="/Home/About" method="post">
    First name:
    <input type="text" name="firstname" id="firstname"><br>
    .....other fields.....
    Last name:
    <input type="text" name="lastname" id="lastname"><br>
</form>
<div id="other">Submit</div>
4

1 に答える 1

3

:notセレクターを使用できます:

$.post("/Home/About", $("#target :not(#lastname)").serialize()); 
于 2013-01-26T12:30:45.937 に答える