Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
419 views
in Technique[技术] by (71.8m points)

javascript - 向下滑动动态元素的动画(slide down animation with dynamic elements)

i want to build a shopping cart to my website.(我想建立一个购物车到我的网站。)

This page dynamicly displays all the items someone has chosen prior in a list.(此页面动态显示列表中某人先前选择的所有项目。) For every item i want to make a slide down toggle link to display more options for each item(我想为每个项目制作一个向下滑动的切换链接,以显示每个项目的更多选项) HTML and PHP(HTML和PHP) <p> <span id="inquiryCartSlideDown" class="linkArrow">change order</span> </p> <div id="moreInfoInquiryCart" class="collapse"> my div with labels and inputs </div> My PHP echos this div as often as the customer has purchased items through a foreach loop.(当客户通过foreach循环购买商品时,我的PHP会频繁地响应该div。) So i get this same div multiple times with the same id.(所以我多次获得相同的div具有相同的ID。) JS(JS) `$(function(){ $("#inquiryCartSlideDown").click(function(){ $("#moreInfoInquiryCart").slideToggle("slow"); }); });` This works but only for the first item.(这有效,但仅适用于第一项。) The problem is probably that i am using id's.(问题可能是我正在使用ID。) But what should i do instead.(但是我应该怎么做。)   ask by AB Meg translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use on function of JQuery which works for dynamic elements as well:-(您可以on对动态元素也起作用的JQuery函数上使用:-)

$(function(){ $('.linkArrow').on('click', function() { $(this).closest(".collapse").slideToggle("slow"); }); }); Hope this helps.!!(希望这可以帮助。!!)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...