【发布时间】:2015-01-02 22:20:42
【问题描述】:
我在 php 中有一个动态添加行的表单(单击按钮后添加了行)。我想用值“xx”填充该字段,我想在 jquery 中完成。
此循环在 jquery 中创建动态添加的行。我想用值“xx”填充添加的字段:
while($personsArrayLength>2){
echo '
<script>
$(document).ready(function(){
var i = 2;
var rowTemplate2 = jQuery.format($("#template2").html());
rowTemplate2.value = "xx";
addRow2();
function addRow2(){
var ii = i++;
$("#app_here2").append(rowTemplate2(ii));
$("#delete_" + ii).click(function(){
$("#row_" + ii).remove();
});
}
});
</script>
';
这里是 html:
function addRows2(){
global $personsError_css;
$personsArray = $_POST['persons'];
JB_var_dump($_POST['whichRow']);
$html = '<table id="template2" align="right" style="display:none; ">
<tr id="row_{0}">
<td><input type="text" size="52" id="persons" name="persons[]" maxlength="100"></td>
<td><img src="/../_img/row_del.png" id="delete_{0}" alt="usun"></td>
</tr>
</table>
<table id="list2" style="margin-left:200px;">
<thead >
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" size="52" name="persons[]" maxlength="100" style="'.$personsError_css.';" value="'.$personsArray[1].'"></td>
<td></td>
</tr>
<tr>
<td colspan="2" id="app_here2"></td>
</tr>
</tbody>
</table>';
return $html;
}
这是正确填写的表格
在这个空字段中,我想添加值“xx”
对不起我的英语。
如何在添加的行中设置值?我应该在我的代码中更改什么? 感谢帮助。
【问题讨论】:
-
您要设置占位符吗?直到人们输入占位符将填充其他文本框的内容..
rowTemplate2.find('input:empty').val('xx')
标签: javascript php jquery forms