douti0467 2013-08-12 05:15
浏览 49

搜索<td>,并编辑另一个<td>的内容

I'm looking to write a piece of a larger program which I would like to search the source html on a website for one of two values "Index 1" or "Index 2" within a unknown number of tags, then edit the tag above the containing "Index 1" or Index 2" (still within the same table row ) to denote a checkbox is checked or unchecked. As an example: I want to achieve all "Index 1" checkboxes on while "Index 2" checkboxes are off. I'm not entirely sure the best way to approach this and am looking for guidance in the right direction. Here is some mock code which may help

<fieldset  class="stackedSection">
<legend >someThings</legend>    <table>
      <tr>
    <td><input name="someId[]" type="checkbox" value="001"></input></td>
    <td><a href="associated?id=001">nameOfAssociatedID001</a> index 1        (<a href="device?id=a01">name1</a>)</td>
  </tr>
      <tr>
    <td><input name="someId[]" type="checkbox" value="002" checked></input></td>
    <td><a href="associated?id=002">nameOfAssociatedID002</a> index 1        (<a href="device?id=a02">name2</a>)</td>
  </tr>
      <tr>
    <td><input name="someId[]" type="checkbox" value="003" checked></input></td>
    <td><a href="associated?id=003">nameOfAssociatedID003</a> index 1        (<a href="device?id=a03">name3</a>)</td>
  </tr>
      <tr>
    <td><input name="someId[]" type="checkbox" value="004" checked></input></td>
    <td><a href="some?id=004">nameOfAssociatedID004</a> index 2        (<a href="device?id=a04">name4</a>)</td>
  </tr>
    </table>
</fieldset>
  • 写回答

1条回答 默认 最新

  • douyue3800 2013-08-12 05:22
    关注

    Just put them inside a form then give the radio buttons same names then HTML will do the trick for you.

    Or if there are more than one radio that you want to check it is advisable that you use checkboxes and just iterate in javascript (using jquery).

    Example:

    $('#tableID tr td').find('input[type="checkbox"]').each(function(){
         if(this.value == "Index 1"){
             this.checked = true;
         }
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法