我有一个php动态添加行的形式(点击按钮后行添加)。我想填充字段值“xx”,我想在jQuery中做到这一点。如何使用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;
}
这是正确填写表格
在这种epty领域我想以增加值“xx”
对不起,我的英语。
如何设置添加行的值?我的代码中应该改变什么? 感谢您的帮助。
你想设置一个占位符?直到人类输入东西时,占位符将填充文本框,否则......'rowTemplate2.find('input:empty').val('xx')' – Mephiztopheles 2014-11-06 12:08:36