单击时获取元素的id(php,jquery,ajax,javascript) [英] Get id of element when click ( php, jquery, ajax, javascript )
问题描述
对不起,这是我的第一个项目,我学到了很多东西。所以,如果有人可以帮助我,我将不胜感激。
I'm sorry, this is my first project and I'm learning a lot. So if someone can help me, I will be grateful.
我的项目中有这个侧栏,其中包含rss链接。我必须使用ajax,所以每当用户点击任何rss链接时,Feed都会显示在屏幕上。
I have this sidebar on my project, which contains rss links. I have to use ajax so each time when user click on any rss link, feeds will appear on screen.
这是我的侧边栏代码:
<div class="col-md-3">
<div class="well" style="width:300px; bottom: 0; top: 50px; position: fixed;">
<div id="sidebar-wrapper" style="overflow-y: scroll; overflow-x: scroll; height: 100%;">
<ul class="list-unstyled">
<li class="nav-header">
<a href="#" data-toggle="collapse" data-target="#userMenu">
<h5><b>Subscriptions </b><i class="glyphicon glyphicon-chevron-down"></i></h5>
</a>
<ul class="list-unstyled collapse in" id="userMenu">
<li><a id="id_1" href="#">Sub_1</a></li>
<li><a id="id_2" href="#">Sub_2</a></li>
<li><a id="id_3" href="#">Sub_3</a></li>
<li><a id="id_4" href="#">Sub_4</a></li>
<li><a id="id_5" href="#">Sub_5</a></li>
<li><a id="id_6" href="#">Sub_6</a></li>
<li><a id="id_7" href="#">Sub_7</a></li>
</ul>
</li>
</ul>
</div>
</div>
有机会获得单击任何链接时每个链接的ID?
There is any chance to get id for each link when any of those links are clicked ?
或者我必须编写一个不同的函数,在哪里为每个id使用ajax?
Or I have to write a different function where to use ajax for each id ?
有人可以告诉我如何只使用ajax一次,而不是七次吗?
我的身体标签中有一个div: div id =changebodywithaxaj
我希望通过每个链接的正确Feed来更改它。
Can someone show me how to use ajax on this only once, not seven times ?
I have a div in my body tag : div id="changebodywithaxaj"
and I want to change it with properly feeds for each link.
提前谢谢。
推荐答案
您可以通过这种方式获取ID,因为更多细节和ajax部分,检查这个小提琴,祝你好运。
http://jsfiddle.net/ea51y1j5/
You can get the ID by this way, for more details and ajax part, check this fiddle, good luck. http://jsfiddle.net/ea51y1j5/
$("#userMenu").children('li').click( function() {
var rssId = $(this).children('a').attr('id');
});
这篇关于单击时获取元素的id(php,jquery,ajax,javascript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!