我想在单击链接时禁用链接,下面是我的代码:
<a class="cmd-7" href="?cmd=7" style="color:#00F; margin-left:15px; text-decoration:underline">Past 7 Days</a>
<a class="cmd-14" href="?cmd=14" style="color:#00F; margin-left:15px; text-decoration:underline">Past 14 Days</a>
<a class="cmd-30" href="?cmd=30" style="color:#00F; margin-left:15px; text-decoration:underline">Past 30 Days</a>
<a class="cmd-custom" href="?cmd=custom" style="color:#00F; margin-left:15px; text-decoration:underline">Set A Custom Date Range</a>这是我的javascript代码:
<script type="text/javascript">
jQuery(function($){
// Get the cmd query parameter
var cmd = getParameterByName('cmd');
if(cmd) {
// Disable the link
$('a.cmd-' + cmd).click(function(event) {
event.preventDefault();
})
// Add a class to allow styling
.addClass('disabled');
}
});
</script>它会产生错误
ReferenceError:未定义getParameterByName
如何删除此错误?
我想当我点击过去7天链接这个链接是禁用或其他链接启用,那么如果我点击过去14天的链接,过去的7天链接是启用的,过去14天的链接是disabled.how我这样做吗?
发布于 2014-01-30 13:01:38
尝试:
<script type="text/javascript">
//var prevClicked;
jQuery(function($){
// Disable the link
$( "a[class*='cmd']" ).click(function(event) {
event.preventDefault();
if(typeof prevClicked!='undefined'){ $("a[class*='cmd-"+prevClicked+"']").attr('href','?cmd='+prevClicked);}
url = $(this).attr('href');
prevClicked = url.split('=')[1];
$(this).attr('href',"javascript:;");
$(this).addClass('disabled'); //adding 'disabled' to the clicked <a> tag
$("a[class*='cmd']").not(this).removeClass('disabled'); //removing 'disabled' from all <a> tags except the one clicked
});
// Add a class to allow styling
});
</script>发布于 2014-01-30 13:16:48
可以将公共类添加到所有链接中,以便可以先启用所有链接,然后禁用以"this“作为引用的当前链接。
就像这样在你的准备工作中
假设您的公共类是“cmd- Suppose”。
$(document).on('click', '.cmd-common', function(event) {
event.preventDefault();
$('.cmd-common').attr('disabled',false);
$(this).attr("disabled", true);
});https://stackoverflow.com/questions/21456570
复制相似问题