Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Jquery和表操作_Php_Jquery - Fatal编程技术网

Php Jquery和表操作

Php Jquery和表操作,php,jquery,Php,Jquery,我在php中通过循环创建了一个表。i、 e.表中的行数将是动态的(1、2、3、4、5等,如我想显示的)。 我希望在最后一个td的每一行中,当我们聚焦时,所有之前的td值都将被计算并显示在最后一个td中 <select name="number" id="number" onchange="document.form2.submit()"> <? for($j=1;$j<=5;$j++) {?> <option value="<?=$j ?>

我在php中通过循环创建了一个表。i、 e.表中的行数将是动态的(1、2、3、4、5等,如我想显示的)。 我希望在最后一个td的每一行中,当我们聚焦时,所有之前的td值都将被计算并显示在最后一个td中

<select name="number" id="number"  onchange="document.form2.submit()">
<? for($j=1;$j<=5;$j++) {?>
    <option value="<?=$j ?>" <?=($j==$_REQUEST['number'])?'selected':'' ?>><?=$j ?></option>
<? } $num=$_REQUEST['number']; ?>
</select>
<table width="100%" border="0"  cellpadding="4" cellspacing="5" id="mytable">
    <thead>
        <tr>
            <th width="35%">Length</th>
            <th width="36%">Width</th>
            <th width="29%">Area</th>
        </tr>
    </thead>
    <tbody>
    <? for($i=0;$i<$num;$i++) {?>
        <tr class="row">
            <td><input type="text" name="length" class="textbox" id="length"/></td>
            <td><input type="text" name="width" class="textbox" id="width" /></td>
            <td><input type="text" name="area" class="textbox" id="area" onfocus="" /></td>
        </tr>
    <? } ?>
    </tbody>
</table>


顺便说一下,ID只能使用一次。您不能多次使用它。

选择行的最后一个
td

$('tr.row td:last-child');
要选择该行最后一个
td
中的
文本框

$('tr.row td:last-child').children('input.textbox')​
为了简化此操作,请不要在页面上重复ID,并在文本框中添加其他类:

<? for($i=0; $i<$num; $i++) {?>
<tr class="row">
    <td><input type="text" name="length" class="textbox length" /></td>
    <td><input type="text" name="width" class="textbox width" /></td>
    <td><input type="text" name="area" class="textbox area" onfocus="" /></td>
</tr>
<? } ?>

你说的专注是什么意思?焦点是您输入元素所做的事情。如果你的意思是“点击”,那么点击前会显示什么?有没有理由不只是在php中计算“面积”并将其放入html中?看一看
<? for($i=0; $i<$num; $i++) {?>
<tr class="row">
    <td><input type="text" name="length" class="textbox length" /></td>
    <td><input type="text" name="width" class="textbox width" /></td>
    <td><input type="text" name="area" class="textbox area" onfocus="" /></td>
</tr>
<? } ?>
$('input.area')​