将动态ID值传递给jQuery div跳转至函数 [英] Pass dynamic id value jquery div jump to function
本文介绍了将动态ID值传递给jQuery div跳转至函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我被困在jQuery div跳到问题.问题是我正在创建动态<a href="" id="1_1"></a>
,而动态div也说<div id="1_1_div"></div>
我正在使用以下jquery函数滚动到特定的div
I am stuck at jquery div jump to problem. The problem is that i am creating dynamic <a href="" id="1_1"></a>
and dynamic div also say <div id="1_1_div"></div>
i am using following jquery function to scroll to a particular div
<script>
$(document).ready(function (){
$("#click").click(function (){
alert ("test");
//$(this).animate(function(){
$('html, body').animate({
scrollTop: $("#div1").offset().top
}, 1000);
//});
});
});
</script>
我的问题是如何将动态ID传递给$("")
任何帮助,我们将不胜感激.
My question is how to pass dynamic id to $("")
Any help would be highly appreciated.
推荐答案
$(document).ready(function (){
$(".click").click(function (){
alert ("test");
var divID = '#' + $(this).attr('id') + '_div';
$('html, body').animate({
scrollTop: $(divID).offset().top
}, 1000);
});
});
并添加<a class="click" ...
这篇关于将动态ID值传递给jQuery div跳转至函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文