[英]Why is my jquery call showing up as undefined?
I'm trying to grab a url from an <a>
tag and display the first paragraph of the url underneath the title. 我正在尝试从
<a>
标记中获取一个网址,并在标题下方显示该网址的第一段。 Currently this returns 'undefined'. 当前,这返回“未定义”。
My Html: 我的HTML:
<section class="community">
<div class="news">
<ul class="article-list">
<li><a href="">This is an article</a></li>
<li><a href="">This is an article</a></li>
<li><a href="">This is an article</a></li>
</ul>
</div>
</section>
My JQuery: 我的JQuery:
var url = $('.community .news ul li a').attr('href .p1');
$.get(url, function(response) {
$('.community .news ul li').append("<p>" + url + "</p>");
});
FYI .p1 is a class surrounding the first paragraph in the url (what I'm trying to display basically) FYI .p1是围绕url中第一段的类(基本上是我要显示的内容)
Only $.load
supports loading page fragments so with that in mind, try this... 仅
$.load
支持加载页面片段,因此请记住这一点...
$('.community .news ul li a[href]').each(function() {
$('<p>').insertAfter(this).load(this.href + ' .p1');
});
you need to simple get your url bu usin below code 您需要简单地在以下代码中获取您的网址
var url = $('.community .news ul li a').attr('href'); var url = $('。community .news ul li a')。attr('href');
i do not understand why you add " .p1" with href ? 我不明白为什么要在href中添加“ .p1”?
try this code to get url 尝试此代码获取网址
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.