使用下面的代码,我可以预先填写表单的输入元素,
<?PHP
$filename = 'txt.txt';
$str = file_get_contents($filename);
for ($y=5; $y<=10;$y++){
if($data[$y][0]=="PROJECT TITLE"){
$projecttitle= $data[$y][1];}
} ?>
<tr>
<th>Project Title: </th>
<td><span class="dropt">
<input id="projecttitle" onkeyup="ProjectTitleValidate()" value="<?php echo $projecttitle ?>" autocomplete="off" type="text" maxlength="50" name="projecttitle" title="Project Title for reference!">
</td>
</tr>
上面的 txt.txt 是,
title: temp_12
但是如何实现这一点,对于这种动态表,
<script>
function buildTable(val)
{
var myTable =document.getElementById("contentTable");
var j=val;
var r1=val;
var rows = [];
var cells = [];
while (myTable.hasChildNodes()) {
myTable.removeChild(myTable.lastChild);
}
for( var i = 0; i < 1; i++ )
{
rows[i] = myTable.insertRow(i);
if(i%3==2)rows[i].addClass("every3rdrow");
cells[i] = [];
for( var x = 0; x < j ; x++ )
{
cells[i][x] =document.createElement((x==0)?"th":"td");
cells[i][x].innerHTML = (x==0)?"<input id=t onchange=ty() name=t[] size=3>":"<input id=t1 onchange=ty1() name=t1[] size=3>";
rows[rows.length - 1].appendChild(cells[i][x]);
}
}
}
buildTable();
</script>
<tr>
<th>Number of Models:<title="Number of Models"></th>
<td><select id="numbermodels" name="numbermodels" onmouseover="buildTable(this.value)" onchange="buildTable(this.value);buildTable4(this.value);">
<option value="1">1</option >
<option selected="selected" value="2">2</option >
<option value="3">3</option >
<option value="4">4</option >
<option value="5">5</option >
<option value="6">6</option >
</select></td>
</tr>
<tr>
<th>Number of heads per model:</th>
<td>
<table id="contentTable" border="1" name="contentTable">
<!-- Fill table programmatically -->
</table></td>
</tr>
和 txt.txt 文件是
Vector: 23 34 43 54
我试图在像 value= 这样的 JavaScript 输入元素中包含 php,但这不会生成表格,有什么方法可以实现吗?