2013-01-19 91 views
0

我正在做一个网页中的转到链接,输入文本放在一边。 goto链接同时出现在网页的顶部和底部。如何获得输入文本点击jQuery链接时

<div class="gotopage"> 
    goto page<input type="text" class="page_i"/> 
    <a href="###" class="Goto">Go</a> 
</div> 

jQuery中,我需要得到链接旁边的文字:

$('a.Goto').live('click',function(){ 
    window.location.href = ...; 
}); 

如何获取文本值,它不应该是ID,用于标识出现两次。

回答

2

使用prev()获得同级文本输入:

$('a.Goto').live('click',function(){ 
    window.location.href = $(this).prev('.page_i').val(); 
}); 
0

自动换行的span标签:

<div class="gotopage"> 
<span>goto page</span><input type="text" class="page_i"/> 
<a href="###" class="Goto">Go</a> 
</div> 

然后选择它

$('a.Goto').live('click',function(){ 
    window.location.href = $(this).closest('span').text(); 
}); 
0

你可以得到的文本通过此代码输入框

<script> 
$('a.Goto').live('click',function(){ 
    txt=$('.gotopage .page_i').val(); 
    alert(txt); 
}); 
</script> 
相关问题