内打开。使用AJAX编写内部链接
我正在尝试编写一些我的第一个 jquery 脚本,但遇到了一些问题...... 我的页面有很长的文本,有很多内部链接( Foo
)。我希望当您单击其中一个 .internal 链接时,href 路径将在
var InternalLink = function() {
$(".internal").click(function(){
var path = $(this).attr("href");
$.ajax({
url: "path",
success: function(data) {
$('#article').html(data);
}
});
});
};
我编写了如下所示的代码,它工作得很好,但我试图将代码推广到具有内部类的每个链接:
$("#article_01").click(function(){
$.ajax({
url: 'contents/article_01.htm',
success: function(data) {
$('#article').html(data);
}
});
});
I am trying to write some of my first jquery scripts but I'm having some problem...
My page have a long text with lot of internal links (<a href="/contents/Foo.htm" class=.internal>Foo</a>
). I'd like that when you click on one of the .internal links, the href path will be opened inside the <div id="article">
.
var InternalLink = function() {
$(".internal").click(function(){
var path = $(this).attr("href");
$.ajax({
url: "path",
success: function(data) {
$('#article').html(data);
}
});
});
};
I wrote the code shown below and it work perfectly but I am trying to generalize the code to every link with internal class:
$("#article_01").click(function(){
$.ajax({
url: 'contents/article_01.htm',
success: function(data) {
$('#article').html(data);
}
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JS:
所以现在您所要做的就是更改
data-ref
以指向您希望 html 加载到其中的 div。JS:
So now all you have to do is change the
data-ref
to point to the div you want the html to load inside of.