1

朋友们,

我编写了以下 JavaScript 来确定用户当前在表格的哪一行。即他们单击了第 4 行上的选择列表。我需要行号然后获取同一行上字段的正确值,然后我可以对其执行一些进一步的处理。

这个 JavaScript 所做的是获取触发项的 id,例如 f02_0004 这告诉我第 4 行第 2 列中的选择列表已被选中。因此,我的 Javascript 仅获取行信息,即 0004,然后使用它来引用该行中的另一个字段,此时仅输出值以显示我具有正确的值。

<script language="JavaScript" type="text/javascript">
   function cascade(pThis){      
      var row = getTheCurrentRow(pThis.id);
      var nameAndRow = "f03_" + row;
      var costCentre = $x(nameAndRow).value;
      alert("the cost centre id is " + costCentre);

}
   // the triggerItem has the name fxx_yyyy where xx is the column number and 
   // yyyy is the row. This function just returns yyyyy    
   function getTheCurrentRow(triggerItem){   
      var theRow = triggerItem.slice(4);
      return theRow;         
}

虽然这行得通,但我不禁觉得我必须重新发明轮子,或者,有内置的我可以使用,或者如果没有,可能有“更好”的方法?

如有需要,我使用 Apex 4.0

提前感谢您提供的任何内容。

4

1 回答 1

2

好吧,你所描述的正是我自己通常做的!

Apex 4.0 中的替代方法是使用 jQuery 来导航 DOM,如下所示:

var costCentre = $(pThis).parents('tr').find('input[name="f03"]')[0].value;

我已经对此进行了测试,并且在我的测试表格中可以正常工作。

于 2010-07-19T16:09:53.600 回答