2015-04-06 44 views
-1

我試圖通過使用$(elem).html()複製表單來打印表單(不涉及服務器端)。問題是用戶輸入的屬性值沒有被捕獲。我設法解決了這個輸入文本區域和輸入複選框使用提供給我的問題how do I print a html form along with its contents的答案,但我一直無法做到textarea相同。以下是我用於文本和複選框字段的代碼。如何設置文本區域的屬性值

function CopyElem(elem) 
{ 

    $('form input[type=text]').each(function() { 
    $(this).attr('value', $(this).val()); 
    }); 

    $('form input[type=checkbox]').each(function() { 
    $(this).attr('checked', $(this).prop("checked")); 
    }); 

    $('form textarea').each(function() { 

    }); 

} 

所以問題是什麼需要textareas?

+1

請檢查http://stackoverflow.com/questions/415602/set-value-of-textarea-in-jquery – Pugazh 2015-04-06 13:54:16

+0

文本區域沒有值屬性。這可能會幫助你'$('form textarea')。text(function(){ return $(this).val(); });' – Satpal 2015-04-06 14:09:11

+0

@Satpal既然'