编辑字段后如何更新(使用jquery或javascript)'的值

How do I update a field (using jquery or javascript) after editing it's value on the table

本文关键字:javascript 的值 jquery 使用 何更新 字段 编辑 更新      更新时间:2023-09-26

我实现了一个购物车,在有人向购物车添加项目后,他们可以更改数量并单击更新进行所需的更改。然而,在它被点击后,我希望它说更新!

现在,如果有人再次点击该字段进行更新,它应该会变回一个显示更新的按钮。

我该怎么做?我不太熟悉jquery或javascript

谢谢。

不确定您是如何启动服务器更新的,但这里有一个您可以使用的简短片段:

    $('document').ready(function(){
       $('#yourInputField').change(function() {
           $('#yourButton').addClass('enable');
        });
         $('#yourButton').on("click",function() {
          //Fire ajax for server, onsuccess is ajax success method
           onsuccess(e){
           $(this).removeClass('enable');
           $(this).addClass('disable');
           };
        });
    });

下面是一个入门的基本示例:

HTML

<div class="item">
    <input class="amount" type="text" />
    <div class="update">
        <button class="update-button" type="button">Update</button>
        <div class="update-message">Updated!</div>
    </div>
</div>

JS

$('.update-button').click(function () {
    // Hide the update button
    $(this).hide()
    // Show the update message
    $(this).siblings('.update-message').show();
});
$('.amount').click(function () {
    // Show the update button
    $(this).closest('.item').find('.update-button').show();
    // Hide the update message
    $(this).closest('.item').find('.update-message').hide();
});

jsfiddle