Mootools:从点击链接的兄弟表节点获取文本

时间:2015-11-08 12:49:59

标签: select mootools siblings

这是情况:

message Person {
  required string name = 1;
  required int32 id = 2;
  optional string email = 3;
  optional string email1 = 4;
  optional string email2 = 5;
  optional string email3 = 6;
  optional string email4 = 7;
  optional string email5 = 8;
  optional string email6 = 9;
  optional string email7 = 10;
  optional string email8 = 11;
  optional string email9 = 12;
  optional string email0 = 13;
  optional string emaila = 14;
  optional string emails = 15;
  optional string emaild = 16;
  optional string emailf = 17;
  optional string emailg = 18;
  optional string emailh = 19;
  optional string emailj = 20;
  optional string emailk = 21;
  optional string emaill = 22;
  optional string emailz = 23;
  optional string emailx = 24;
  optional string emailc = 25;
  optional string emailv = 26;
  optional string emailb = 27;
  optional string emailn = 28;
  optional string emailm = 29;
  optional string emailkk = 30;
}

所有名称都是链接。选中后,它们会通过将名称传递给快速的mysql查询来加载表的其余部分以进行编辑。但是因为我得到了傻瓜,所以我需要抓住身份证来传递。我还需要它来更新更正(和正确!)的记录。

所以,使用MooTools,当我点击链接时,如何从邻近的兄弟中获取文本?地狱,即使只是简单的'JS将会做。

这是现有的功能:

| ID | Name   | ...
+----+--------+---
| 12 | Henry  | ...     a whole list of names, ids,&c ...you get the idea
+----+--------+---
| 13 | Julia  | ...
+-------------+---
...

由于表中有多行,我无法为每个ID function loadRecord(aName) { console.log("loadRecord called with: "+aName); user = $('submitterName').value; id = $('table-id').text; // THIS IS THE PROBLEM RIGHT HERE. >_< console.log('with user: '+user); $('recordName').value = aName; $('addRecordButton').value = 'Update Record'; $('addRecordData').action='_php/updateRecord.php'; // this isn't working either... var action=$('addRecordData').action; console.log(action); checkUserDB(aName,user,id); } 分配唯一标识符以获得任何好处。我仍然试图拉出与被点击的链接相关的table-id文本。

我希望我很清楚。任何帮助或照明将不胜感激。

TIA工作人员!

WR!

1 个答案:

答案 0 :(得分:0)

以下是解决方案

  

<强> HTML

<!--Change your HTML-->
<table>
  <tr>
    <th>ID</th>
    <th>Name</th>
  </tr>
  <tr>
    <td>12</td>
    <td><a>Henry</a></td>
  </tr>
  <tr>
    <td>13</td>
    <td><a>Julia</a></td>
  </tr>
</table>
  

<强> MooTools

window.addEvent('load', function(){
  window.addEvent('click:relay(a)', function(event){//Add your selector inside relay
    event.preventDefault();
    console.log($(this).getParent('td').getPrevious().get('html'));
    //Add Your AJAX code here
  });
});
  

您要附加 click event 以锚定 selecting   的 parent http://mootools.net/core/docs/1.5.2/Element/Element#Element:getParent)   然后,因为您在 previous 中有ID   的 element http://mootools.net/core/docs/1.5.2/Element/Element#Element:getPrevious)   你可以 grab the previous element and get it's HTML

您可以在此处查看笔http://codepen.io/arifmahmudrana/pen/yYQeJX