Getting value of another tag
In the below code onclick
edit how can the value of tag test be obtained in the edit function:
<script>
function edit(a)
{
}
var a= <tr class="clickable"><td id="userval" BGCOLOR="#FF6699"><label id=&qu开发者_如何学Goot;test">' + a + '</lable> <IMG SRC="edit.gif" onclick="javascript:edit(test.value);" > ></td></tr>
</script>
Assuming jQuery usage:
<script>
function edit(elem)
{
$(elem).siblings('label#test').html();
}
var a= '<tr class="clickable"><td id="userval" BGCOLOR="#FF6699"><label id="test">' + a + '</label> <IMG SRC="edit.gif" onclick="javascript:edit(this);" > ></td></tr>
</script>
I take it a
is actually a string? (it's not in your example, but it's concatenated as though it were)
function edit(a)
{
var value = $(a).find('#test').text();
}
var value = $("#test", $(a)).text()
精彩评论