链接与按钮的困境
任何人都可以阐明这种情况:我有一个在模式中打开的链接,我添加了一个链接和一个设置为转到同一网址的按钮。如果我单击链接,模式将转到链接,并正确显示文章。如果我单击该按钮,它会显示嵌入在页面上的文章。
这是网址,单击 newtest2
http: //zaazoolive.thewebbusters.com/index.php?option=com_content&view=category&id=1&Itemid=2
这是代码
<head>
<script type="text/javascript">
function change_url(){
window.location.href="http://zaazoolive.thewebbusters.com/index.php?option=com_content&view=article&id=1:newtest&catid=1:test&Itemid=2"
}
</script>
<a href="http://zaazoolive.thewebbusters.com/index.php?option=com_content&view=article&id=1:newtest&catid=1:test&Itemid=2">next</a>
</head>
<body>
<button onclick="location.href='http://zaazoolive.thewebbusters.com/index.php?option=com_content&view=article&id=1:newtest&catid=1:test&Itemid=2'">Next</button>
</body>
</html>
Can anyone shed some light to this situation: I have a link that opens in a modal, i add a link and a button that are set to go to the same url. If i click the link, the modal goes to the link, and shows the article properly. If i click the button, it shows the article embedded on the page.
Here's the url, click on newtest2
http://zaazoolive.thewebbusters.com/index.php?option=com_content&view=category&id=1&Itemid=2
Here's the code
<head>
<script type="text/javascript">
function change_url(){
window.location.href="http://zaazoolive.thewebbusters.com/index.php?option=com_content&view=article&id=1:newtest&catid=1:test&Itemid=2"
}
</script>
<a href="http://zaazoolive.thewebbusters.com/index.php?option=com_content&view=article&id=1:newtest&catid=1:test&Itemid=2">next</a>
</head>
<body>
<button onclick="location.href='http://zaazoolive.thewebbusters.com/index.php?option=com_content&view=article&id=1:newtest&catid=1:test&Itemid=2'">Next</button>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一个明显的区别,即链接调用
window.location
,而按钮仅设置location
,但这在语义上是相同的。您看到的弹出窗口是由 JavaScript 创建的。因此,该链接仅用于其 url,但当您单击它时,会执行一个脚本,异步加载内容并在弹出窗口中显示它。
该脚本不会影响按钮(尽管可以)。找到执行此操作的脚本并将其也应用到按钮。
There is a apparent difference, being that the link calls
window.location
, while the button just setslocation
, but this is semantically the same.That popup you got is created by JavaScript. So the link is just used for its url, but when you click it, a script gets executed that loads the content asynchronously and shows it in a popup.
This script does not affect the button (though it could). Find the script that does this and apply it to the button too.
解决方法可能是:
编辑:虽然它可以工作,但不是推荐的代码,因为 HTML 规范明确指出使用项目标记是无效的,因此仅将此视为解决方法。
PS 为什么在节头中使用
?
A workaround could be:
Edit: Although it's working, is not a recommended code, as HTML spec clearly says that using tag for item is invalid, so treat this ONLY as a workaround.
P.S. Why are you using
<a></a>
in section head?