HTML结构如下<tr>
<td><a class="gotop" href="javascript:void(0)">顶1</a></td>
</tr>
<tr>
<td><a class="gotop" href="javascript:void(0)">顶2</a></td>
</tr>
<tr>
<td><a class="gotop" href="javascript:void(0)">顶3</a></td>
</tr>
<tr>
<td><a class="gotop" href="javascript:void(0)">顶4</a></td>
</tr>
gotop绑定事件,找到前一个gotop:方法一:
$('.gotop').click(function(){
var prev=$(this).parents('tr').prev().find('.gotop')
})
方法二:
$('.gotop').click(function(){
var i=$('.gotop').index($(this)
var pi=i-1
pi=(pi>=0)?pi:0
var prev=$('.gotop:eq('+pi+')')
})方法三 ,此方法错误。
$('.gotop').click(function(){
var prev=$(this).prev('.gotop')
})求教有没更简单的方式可以找到上一个gotop?
试过prev,prevAll,prevUnitl,但是似乎prev开头的只能找同一个等级的,即,一个标签下的,请指教!
<td><a class="gotop" href="javascript:void(0)">顶1</a></td>
</tr>
<tr>
<td><a class="gotop" href="javascript:void(0)">顶2</a></td>
</tr>
<tr>
<td><a class="gotop" href="javascript:void(0)">顶3</a></td>
</tr>
<tr>
<td><a class="gotop" href="javascript:void(0)">顶4</a></td>
</tr>
gotop绑定事件,找到前一个gotop:方法一:
$('.gotop').click(function(){
var prev=$(this).parents('tr').prev().find('.gotop')
})
方法二:
$('.gotop').click(function(){
var i=$('.gotop').index($(this)
var pi=i-1
pi=(pi>=0)?pi:0
var prev=$('.gotop:eq('+pi+')')
})方法三 ,此方法错误。
$('.gotop').click(function(){
var prev=$(this).prev('.gotop')
})求教有没更简单的方式可以找到上一个gotop?
试过prev,prevAll,prevUnitl,但是似乎prev开头的只能找同一个等级的,即,一个标签下的,请指教!
解决方案 »
- Coolite和ExtJs的控件对应关系是怎样的?
- Ext 中将后台id的值传给window组件中TabPanel怎么做?
- 百度地图加标记时,弹出的需要输入信息的信息提示框里有文本输入框
- 又遇到个蹊跷的问题
- 请教高手,如何替换超文本标签?
- [求助]如果控制用<EMBED>嵌入的Flash文件的被点击后的操作?
- 请问怎么能做到form提交而form中的button不提交?
- 请问有没有将数值型转换成货币型的函数
- js能很好的控制table,象控制grid一样吗?
- chrome调试
- 从网上找了一个显示特效图片的脚本,想在点击不同的图片时打开不同超链接,请问该怎么实现
- iframe submit提交,返回页面显示到主窗口上了
<tr>
<td><a class="gotop" href="javascript:void(0)">顶1</a></td>
<td><a class="godown" href="javascript:void(0)">沉1</a></td></tr>
<tr>
<td><a class="gotop" href="javascript:void(0)">顶2</a></td>
<td><a class="godown" href="javascript:void(0)">沉2</a></td></tr>
var $gt = $('.gotop');
$gt.click(function(){
var index = $gt.index(this)
index && alert("上一个是:"+$($gt[index-1]).text() )
})
另有一不明白。index && alert("上一个是:"+$($gt[index-1]).text() )这个 && “与” 作用 后,如果是第一个 为什么就不alert了?alert 难道可以看成一个true or false么?觉得这个挺有意思的,请指教!
if(index) alert("上一个是:"+$($gt[index-1]).text() )