2015-05-12 39 views
0

這是我的jQuery,我有它正常工作,但一旦我的行被添加用戶輸入的輸入仍然存在,並沒有清除。我該如何解決?需要在輸入文字不顯示用戶輸入一次發送

// Removing menu rows 
    $('.menu-items').on('click', '.delete', function(){ 
     $(this).closest('.menu-row').remove(); 
    }); 

// HTML 
var MENU_ROW_TEMPLATE = '<div class="menu-row"><span class="item-description">$description</span><div class="control-items"><span class="item-price">$price</span><span class="delete">X</span></div></div>' 

// Adding menu rows 
$('.menu-category').on('click', 'button', function(){ 
    var $row = $(this).closest('.add-item'); 
    var name = $row.find('input').first().val(); 
    var price = $row.find('input').last().val(); 

    var newRowHtml = MENU_ROW_TEMPLATE.replace('$description', name).replace('$price', price); 

    var $newRow = $(newRowHtml); 

    var $lastMenuRow = $row.closest('.menu-category').find('.menu-row').last(); 

    $newRow.insertAfter($lastMenuRow); 
}); 

對不起,我的解釋能力很差。

+1

試試這個:Input.val( ''); – Rayon

回答

1

清除名稱和價格,你得到的值後...

... 
var name = $row.find('input').first().val(); 
var price = $row.find('input').last().val(); 
$row.find('input').first().val(''); 
$row.find('input').last().val(''); 
...