改变HTML的输入值 [英] HTML- Altering Input Value
问题描述
$('#table1')。html($('#table1' ).html()+< next_table_line>);
。这会导致输入字段恢复为其值
属性中显示的值,当使用 $('#input1' ).val(< some_value>);
setter或手动输入数据。有谁知道我的问题的解决方案?我需要能够在不丢失数据的情况下向表中添加行,但我无法弄清楚如何执行此操作。 解决方案($('#table1')。html()+< next_table_line>); $> C $ C>。您应该追加到您的表格。以下示例小表:
< table id =test>
< tr>< td>测试< / td>< / tr>
< / table>
现在,要添加一个新行,不要重写整个表格HTML,只需追加!
$(#test)。append(< tr>< td>请参阅im new!< / td> ;< / TR>中);
演示: http://jsfiddle.net/uB2Rq/1/
I recently posted a similar question, but after some discussion, the question turned out to be quite a bit different than it was originally stated, so I thought it best to post this as a new question. I am trying to use an input field to show a total (I would consider using another element type, but I need to do the same thing in other places where an input field is actually required, so I may as well fix the problem now). The problem is that the HTML of the table containing these fields needs to be reloaded on occasion, i.e. in table creation, I use the Jquery $('#table1').html($('#table1').html() + <next_table_line>);
. This causes the input field to revert to the value displayed in its value
attribute, which doesn't change when I use the $('#input1').val(<some_value>);
setter or when I enter data manually. Does anyone know of a solution to my problem? I need to be able to add rows to the table without loosing my data, but I can't figure out how to do this.
You're reloading your entire table with the line $('#table1').html($('#table1').html() + <next_table_line>);
. You should be appending to your table instead. Take the following sample small table:
<table id="test">
<tr><td>test</td></tr>
</table>
Now, to add a new row, dont re-write the entire table HTML, just append!
$("#test").append("<tr><td>See im new!</td></tr>");
Demo: http://jsfiddle.net/uB2Rq/1/
这篇关于改变HTML的输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!