开发者

Getting value of another tag

开发者 https://www.devze.com 2022-12-23 17:05 出处:网络
In the below code onclick edit how can the value of tag test be obtained in the edit function: <script>

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>&nbsp;&nbsp;&nbsp; <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>&nbsp;&nbsp;&nbsp; <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()
0

精彩评论

暂无评论...
验证码 换一张
取 消