Closed kannafay closed 7 months ago
You should be able to do it by calling the preventDefult in capture phase or using the filter option. pjax ignores the cancelled events. So this is a matter of event handling, not pjax. However, I'll enhance the link option so that the filter option does not have to be used.
My JavaScript programming skills are very poor, I directly introduce js into script
tag. Can you give an example with this code: when I click on span
, I can execute the url
in span
normally, without executing tag a
's Ajax. Write with simple script tags
Thank you very, very, very much!!!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>home</title>
<style>
a {
display: block;
width: 200px;
height: 200px;
background-color: #7fffd4;
}
span {
display: block;
width: 100px;
height: 100px;
background-color: #ffc0cb;
}
a:hover {
background-color: #7fffd480;
}
span:hover {
background-color: #ffc0cb80;
}
</style>
</head>
<body>
<div id="pjax-box"></div>
<a href="/page1.html">
<span data-href="/page2.html">Page 2</span>
Page 1
</a>
</body>
</html>
i need help
Thank you very much to the developers. This JavaScript plugin is really very convenient. But I have a headache problem during use.
My HTML structure is quite unique, and it looks like this:
As is well known, in HTML, tag
<a>
cannot contain tag<a>
, which means tag<a>
cannot be nested. So I put a tag<span>
in tag<a>
and added adata-href
attribute to it, with the value of the URL. I want to correctly redirect to the URL address of the tag when clicking<span>
and execute Ajax. I have been searching for documents for a long time and I don't know what to do. All I know is that I can use thepreventDefult()
andstopPropagation()
methods to prevent default behavior and bubbles. And I found that the link attribute seems to be only valid for the tag<a>
.If anyone can help me, I would really appreciate it!!!