2

在我的网络应用程序中,我有编辑个人资料页面。在editprofile页面中,它们有很多字段,例如

Name            : <input type="text" name="name"/>
Location        : <input type="text" class="geolocation" name="location">
Birthdata       : <input type="date" name="dob">
Profile Picture : <input type="file" name="photo"/>

我只想发回已编辑字段的数据,而不是所有字段。

4

2 回答 2

4

我通常会在后端做这样的事情....但是根据您的要求,您可以删除未更改的输入。当您生成 html 时,您可以定义一个额外的数据属性。我会这样做:

HTML:

<form id="myform">
    <input type="text" id="Name" data-initial="Foo" value="Foo" />
    <input type="text" id="Location" data-initial="Bar" value="Bar" />
    <input type="submit" value="Submit" />
</form>

JS:

$("#myform").submit( function() {
    $(this).find("input").filter( function() {
        $this = $(this);
        return $this.data("initial") == $this.val();
    }).remove();
});

http://jsfiddle.net/uLe7T/
我在小提琴中添加了一个警报,因此您可以看到它们在提交表单之前被删除

于 2013-07-19T13:03:09.660 回答
2

jsFiddle

HTML

<input id="test" type="text" value="Some Text" data-value="Some Text">

JS

$('#test').blur(function() {
    el = $(this);
    if (el.val() != el.attr('data-value')) {
        console.log('Edited');
    } else {
        console.log('Not Edited');
    }
});
于 2013-07-19T13:01:44.323 回答