2012-02-03 80 views
0

我可以找到一種方法來獲取id =「DropDownListA」。但是,我必須使用get prev ID-value form input =「text」

獲得的ID值不知何故$(this).closest('input').attr('id')不工作

<td align="right"> 
<div class="farvorit_field" id="DivDropDownListA"> 
<input type="text" id="DropDownListA" name="customerGroup" value="" size="35"> 
    <a href="#" title='See farvorits customers.'> 
    <img onClick="alert($(this).parent('a').siblings(':text').attr('id'));" src="../img/info.gif" border="0"> 
    </a> 
</div> 
</td> 
+0

這是什麼? – locrizak 2012-02-03 20:30:46

+0

@locrizak,img標籤 – Joe 2012-02-03 20:31:44

回答

4

使用此。

$(this).parent().prev().attr('id') 

.parent()會給錨元素,然後調用它.prev()會給input元素。

Demo

0

如果它是一個ID它應該是在頁面上只有一個,何必把事情複雜,避免簡單$('#DropDownListA').attr('id')? 如果您絕對必須使用單詞this,請使用@ ShankarSangoli的解決方案。