如果网页在HTML/JavaScript中不可用,请转到其他链接
在HTML或JavaScript中,当用户单击某个链接时,是否有任何选项,如果该链接可用,则单击完成,如果没有,则单击另一个链接 以下是我的部分代码:如果网页在HTML/JavaScript中不可用,请转到其他链接,javascript,jquery,html,Javascript,Jquery,Html,在HTML或JavaScript中,当用户单击某个链接时,是否有任何选项,如果该链接可用,则单击完成,如果没有,则单击另一个链接 以下是我的部分代码: <div id="sidebar-collapse" class="col-sm-3 col-lg-2 sidebar"> <ul> <li><a href="/returns"><span class="glyphicon glyphicon-log-in"></spa
<div id="sidebar-collapse" class="col-sm-3 col-lg-2 sidebar">
<ul>
<li><a href="/returns"><span class="glyphicon glyphicon-log-in"></span> Returns</a></li>
<li class="active"><a href="/pay_reco" target="_blank"><span class="glyphicon glyphicon-log-in"></span> Payment Recouncillation </a></li>
<li ><a href="/pay_get" target="_blank"><span class="glyphicon glyphicon-log-in"></span> Payment Get </a></li>
<li><a href="/import"><span class="glyphicon glyphicon-log-in"></span> Import </a></li>
<li>
<!-- Here I want to add Two link in a href tag if first link does not
available (web page not available) then it go to another link
<!-- <object data="http:/127.0.0.1:9004" type="href" > -->
<a target="_blank" href="http://127.0.0.1:9001">
<span class="glyphicon glyphicon-log-in"></span>
ComPare
</a>
</li>
<li><a target="_blank" href="http://127.0.0.1:9000"><span class="glyphicon glyphicon-log-in"></span> Portal </a></li>
-
第1步:更新HTML代码,如下所示
<a id="selector" href="javascript:void(0)">
<span class="glyphicon glyphicon-log-in"></span>
ComPare
</a>
我在上为这个案例创建了jQuery插件
与另一个
HTML:
就这些!:) 你的li没有父ul?你所说的点击链接是什么意思,如果该链接可用,那么点击该链接,如果不可用,则点击另一个链接。@guradio ya只需将部分代码和ul,我想如果网页在第一个链接上不可用,那么它将打开第二个链接。为什么您会在文档中放置指向您自己网站的无效链接?您能否在代码中添加一些注释,也许可以解释您发布的代码与您的问题有何关联asked@user-几乎任何事情都有可能
$(function(){
$('body').on('click', '#selector', function() {
$.ajax({
type: "GET",
url: "http://127.0.0.1:9001",
complete: function(xhr, textStatus) {
if(xhr.status == 200) window.location = "http://127.0.0.1:9001";
else window.location = "http://127.0.0.1:9004";
}
});
})
})
<a href="http://127.0.0.1:9001" data-another="http://127.0.0.1:9004">Link Text</a>
$(function() {
$('a').another();
})