jQuery-将表单数据输出到表中
使用jQuery,如何输出(和附加)表单中提交的值 例如,我输入一个名称,它将显示为一个新的表行,其中包含表单中的名称jQuery-将表单数据输出到表中,jquery,forms,input,output,Jquery,Forms,Input,Output,使用jQuery,如何输出(和附加)表单中提交的值 例如,我输入一个名称,它将显示为一个新的表行,其中包含表单中的名称 <form> Name:<input type="text" /> <input type="submit" /> </form> <table> <tr> <th>Name</th> </tr> // Here the name should be appended.
<form>
Name:<input type="text" />
<input type="submit" />
</form>
<table>
<tr>
<th>Name</th>
</tr>
// Here the name should be appended...within a <tr><td></td></tr>
</table>
姓名:
名称
//在这里,名字应该被附加在…一个
谢谢 下面是一个简单的例子:
$('form').on('submit', function (e) {
e.preventDefault();
var newName = $('form').find('input[type="text"]').val();
$('table').append('<tr><td>' + newName + '</td></tr>')
});
$('form')。关于('submit',函数(e){
e、 预防默认值();
var newName=$('form').find('input[type=“text”]).val();
$('table')。追加(“”+newName+“”)
});
是否有办法单击该行,文本(名称)将再次出现在表单中,以便编辑?也许是这样的$('td',行)。单击(函数(){$(this).replaceWith(“+newName+”);});