1

我引用的页面在这里:

http://jjnursingnotes.com/NOV12/

JQuery 页面位于此处:

http://jjnursingnotes.com/NOV12/jquery.expander.js

单击“阅读更多”后,我希望页面跳转到标题(<h1>)或 div 层的开头(<div class="expander" id="sect##" > ) 在您单击“阅读少”后在该部分的开头。目前,“阅读少”按钮的代码如下所示:

      if ( o.userCollapse && !$this.find(o.lessSelector).length ) {
        $this
        .find(detailSelector)
        .append('<br><br><span class="' + o.lessClass + '">' + o.userCollapsePrefix + '<a href="#">' + o.userCollapseText + '</a></span><br><br>');
      }

我的标题都直接在前面指定了名称(001、002 等),我的猜测是简单地将 #001、#002 等添加到 JQ 代码中的链接中。问题是这个脚本定义了页面上的每个“阅读少”按钮,因此每个按钮的变量需要不同。我在正确的轨道上,还是有更有效的方法来做到这一点?

先感谢您。我显然是所有 JS 和 JQuery 方面的新手!

4

2 回答 2

1
$('.expander .read-more').click(function(e){
 $('html,body').animate({ scrollTop: $(e.target).closest('.expander').offset().top}, "slow");
})

你去吧:)

于 2012-12-07T16:39:19.113 回答
0

而不是<a href="#">为什么不只使用<a href="#sect##">. 然后“少读”将在没有任何 JS 的情况下工作

于 2012-12-07T16:31:12.450 回答