[英]Credit link not work according to the given my script
Well i am coding a script which will avoid editing of credits here is my total page code: 好吧,我正在编写一个脚本,这将避免编辑学分这里是我的总页面代码:
//start the script after loading the page
$(document).ready(function(){
//get the elements from page
var urlvalue1 = document.getElementById("#mycredit").href;
//correct link
if (urlvalue1 == "http://themedaddy.net" )
{window.location.replace("#");
}
//edited link
else{
window.location.replace("http://themedaddy.net");
}
But it is not working even i have added the following html code in the body section and linked the jquery script to it. 但即使我在body部分添加了以下html代码并将jquery脚本链接到它,它也无法正常工作。
<a href="http://themedaddy444444.net" id="mycredit">ThemeDaddy</a>
According to the script it must need to get redirected as the link value is not satisfying. 根据脚本,它必须被重定向,因为链接值不满意。
wrap up the redirect code inside the click event of the anchor tag. 将锚定代码的click事件中的重定向代码包装起来。
$('a#mycredit').on('click',function(e){
e.preventDefault();
//correct link
if (urlvalue1 == "http://themedaddy.net" )
window.location.replace("#");
else{//edited link
window.location.replace("http://themedaddy.net");
}
});
Its working fine you have only mistakenly written #mycredit instead of mycredit while selecting the anchor tag. 它的工作正常你在选择锚标签时只错误地写了#mycredit而不是mycredit。
$(document).ready(function(){
var urlvalue1 = document.getElementById("mycredit").href;
if (urlvalue1 == "http://themedaddy.net" )
{
window.location.replace("#");
}
//edited link
else{
window.location.replace("http://themedaddy.net");
}
});
</script>
<a href="http://themedaddy444444.net" id="mycredit">ThemeDaddy</a>
See this is working absolutely fine 看到这个工作绝对没问题
In selecting elements with getElementById we do not need to put # sign before Id :) 在使用getElementById选择元素时,我们不需要在Id之前放置#符号:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.