2015-11-08 60 views
0

这里的情况:MooTools的:从点击链接的兄弟表节点文本

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

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

所以,使用MooTools,当我点击链接时,如何从邻居兄弟中获取文本?地狱,甚至只是普通的'JS会做的。

这里的现有功能:

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); 
} 

,因为有多个行的表,我无法唯一标识符分配给每个ID 任何益处。我仍然试图拉取与点击链接相关的表格ID的文字。

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

TIA船员!

WR!

+0

笔可以粘贴你的HTML的一个例子吗?并解释你认为'$('table-id')。text'的作用?那个字符串总是一样的吗?你为什么不使用MooTools的get('text')',为什么不在像'data-'字段那样点击的链接中添加你想要的ID? – Sergio

+0

$('table-id).text返回元素中的文本。不知道如何实现moo-data插件,或者我会使用数据字段。 – WhiteRau

回答

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 parenthttp://mootools.net/core/docs/1.5.2/Element/Element#Element:getParent) 然后当你在previous elementhttp://mootools.net/core/docs/1.5.2/Element/Element#Element:getPrevious) 可以有ID grab the previous element and get it's HTML

您可以点击这里http://codepen.io/arifmahmudrana/pen/yYQeJX

+0

优秀!我有结构,感谢代码。你解释得非常清楚,我非常感谢,因为我明白解决方案。 – WhiteRau

+0

@WhiteRau谢谢,然后请upvote&选择它作为正确的答案。 –

相关问题