<tr id="r1">
<td noWrap  rowspan=3>项目1</td><td noWrap  rowspan=3>10</td><td noWrap  rowspan=3><INPUT type=text size='10'  name=cutM100421041374841 id=cutM100421041374841  value=0></td>
<td noWrap><input name="M100421041374841" type="checkbox"   onclick="cutscore(this);" value="5" >戴手表</td>
</tr>
 
<tr id="r2">
<td noWrap><input name="M100421041374841" type="checkbox"   onclick="cutscore(this);" value="2" >内容04</td>
</tr>

<tr id="r3">
<td noWrap><input name="M100421041374841" type="checkbox"   onclick="cutscore(this);" value="3" >戴帽子</td>
</tr>

 
<tr id="r4">
<td noWrap  rowspan=1>项目17</td><td noWrap  rowspan=1>20</td><td noWrap  rowspan=1><INPUT type=text size='10'  name=cutM100512056391014 id=cutM100512056391014  value=0></td>
<td noWrap><input name="M100512056391014" type="checkbox"   onclick="cutscore(this);" value="4" >内容09</td>
</tr>
如果我点击r2里面的checkbox,触发事件onclick="cutscore(this);"如何把这个value=2添加到r1的第二个td的INPUT type=text里面去,function cutscore(obj){
        var tr=obj.parentElement.parentElement
var cut=obj.parentElement.parentElement.cells[2].firstChild
alert(cut.id)
}
点击第一行的checkbox,正常,
点击第二行的checkbox,报错,
要用DOM的方法哦,

解决方案 »

  1.   

    http://topic.csdn.net/u/20100519/21/a190fed6-1f1a-44ac-b4e4-ad35a07d1209.html我刚刚回复了类似的帖子 阁下移步去看看
      

  2.   

    晕死,
    我把你的文件复制粘贴做成asp文件,在IE没效果啊,
      

  3.   

    怎么说呢,还是有点不一样的,我这个问题最主要问题是涉及到rowspan啊,我再想想把,正好晚上没事,别的办法也能做,但是感觉JS操作DOM很爽,想通过这个来做,呵呵
      

  4.   

    我如果定位到1个tr了,怎么样操作能定位到这个tr的上面1行的tr,。。
      

  5.   

    参考:
    <script>
    function cutscore(obj,preL){
        var tr=obj.parentElement.parentElement
        var cut=obj.parentElement.parentElement
        for(var i=0;i<preL;i++)cut=cut.previousSibling;
            cut=cut.cells[2].firstChild
        //alert(cut.id)
        cut.value=obj.value;
    }
    </script>
    <table border=1>
    <tr id="r1"> 
    <td noWrap rowspan=3>项目1</td>
    <td noWrap rowspan=3>10</td>
    <td noWrap rowspan=3><INPUT type=text size='10' name=cutM100421041374841 id=cutM100421041374841 value=0></td>
    <td noWrap><input name="M100421041374841" type="checkbox" onclick="cutscore(this,0);" value="5" >戴手表</td> 
    </tr> 
     
    <tr id="r2"> 
    <td noWrap><input name="M100421041374841" type="checkbox" onclick="cutscore(this,1);" value="2" >内容04</td> 
    </tr><tr id="r3"> 
    <td noWrap><input name="M100421041374841" type="checkbox" onclick="cutscore(this,2);" value="3" >戴帽子</td> 
    </tr> 
    <tr id="r4"> 
    <td noWrap rowspan=1>项目17</td>
    <td noWrap rowspan=1>20</td>
    <td noWrap rowspan=1><INPUT type=text size='10' name=cutM100512056391014 id=Text1 value=0></td>
    <td noWrap><input name="M100512056391014" type="checkbox" onclick="cutscore(this,0);" value="4" >内容09</td> 
    </tr>
    </table>