2011-06-06 50 views

回答

1

您的标签更改为

<a href="#" class="aDg">{name}</a> 

然后

$('#tableDg tbody tr td a.aDg').live('click', function(){ 
    alert("AD"); 
    alert($(this).text()); 
    alert($('input', $(this).parent().next()).val()); 
}) 

Link

这将给该函数调用它的元素的引用 -

如果使用Firefox和延伸Firebug

1

当你打电话给你秀()函数通this您可以改用警报的console.log。然后,您的show()函数可以使用像parentNode这样的属性在DOM中工作。

以下内容并不意味着要做你想做的最漂亮或最好的方式;相反,它是一个让你开始的样本。欲了解更多信息,请参阅:

https://developer.mozilla.org/en/Gecko_DOM_Reference/Introduction

https://developer.mozilla.org/en/DOM/element

<a href="javascript:void();" onclick="show(this);">  

function show(elmnt) { 
    // elmnt is the <a> 
    var _td = elmnt.parentNode; // the <a> element's parent <td> 
    var _tr = _td.parentNode; // the row 
    var thirdTD = _tr.cells(2); // the third <td> in the <tr> 
    var _input = thirdTD.getElementsByTagName("input")[0]; // the first <input> in that cell 
    alert(_input.value); // the {host} value 
}