禁用 link 客户端
Disabling a link client-side
我有一个按钮,单击它会隐藏整个页面中的所有 Link。
<input type="button" class="switch" value="switch" isValue="0" />
脚本是:
<script>
$(document).on('click', '.switch', function () {
var v = $(".switch").attr("isValue");
if (v == 1) {
$(".switch").attr("isValue", "0");
$(".dim").show();
}
else {
$(".switch").attr("isValue", "1");
$(".dim").hide();
}
});
</script>
问题:
- 我需要一个开关来隐藏我所有的 Links
- 我需要我的 Links 看起来像是被禁用而不是隐藏。
我需要的:
- 如何替换按钮使其成为开关?
- 因为每当我单击该按钮时,它都会隐藏我页面中的所有 Link,对吗?我可以只使用 css 这样看起来它只是禁用而不是隐藏因为禁用不会在 link.
上工作
我不希望我的 link 被隐藏,而只是被禁用。
我不确定你说的开关是什么意思。也许你可以使用单选按钮?
要回答您的第二个问题,您可以使用 pointer-events
CSS 样式使 link 不可点击。
.dim.disabled {
pointer-events: none;
}
那么 JS 将是:
$(document).on('click', '.switch', function () {
var v = $(".switch").attr("isValue");
if (v == 1) {
$(".switch").attr("isValue", "0");
$(".dim").removeClass("disabled");
}
else {
$(".switch").attr("isValue", "1");
$(".dim").addClass("disabled");
}
});
您也不应该创建像 isValue
这样的自定义属性。如果需要在元素中存储自定义数据,请使用 .data()
。所以 $(".switch").attr("isValue", "1")
变成 $(".switch").data("isValue", 1);
超链接没有禁用属性。如果您不想链接某些内容,那么您需要删除它的 href 或将 href 替换为 data-href 属性,然后在您想要再次激活时将其替换为 href 属性。
我有一个按钮,单击它会隐藏整个页面中的所有 Link。
<input type="button" class="switch" value="switch" isValue="0" />
脚本是:
<script>
$(document).on('click', '.switch', function () {
var v = $(".switch").attr("isValue");
if (v == 1) {
$(".switch").attr("isValue", "0");
$(".dim").show();
}
else {
$(".switch").attr("isValue", "1");
$(".dim").hide();
}
});
</script>
问题:
- 我需要一个开关来隐藏我所有的 Links
- 我需要我的 Links 看起来像是被禁用而不是隐藏。
我需要的:
- 如何替换按钮使其成为开关?
- 因为每当我单击该按钮时,它都会隐藏我页面中的所有 Link,对吗?我可以只使用 css 这样看起来它只是禁用而不是隐藏因为禁用不会在 link. 上工作
我不希望我的 link 被隐藏,而只是被禁用。
我不确定你说的开关是什么意思。也许你可以使用单选按钮?
要回答您的第二个问题,您可以使用 pointer-events
CSS 样式使 link 不可点击。
.dim.disabled {
pointer-events: none;
}
那么 JS 将是:
$(document).on('click', '.switch', function () {
var v = $(".switch").attr("isValue");
if (v == 1) {
$(".switch").attr("isValue", "0");
$(".dim").removeClass("disabled");
}
else {
$(".switch").attr("isValue", "1");
$(".dim").addClass("disabled");
}
});
您也不应该创建像 isValue
这样的自定义属性。如果需要在元素中存储自定义数据,请使用 .data()
。所以 $(".switch").attr("isValue", "1")
变成 $(".switch").data("isValue", 1);
超链接没有禁用属性。如果您不想链接某些内容,那么您需要删除它的 href 或将 href 替换为 data-href 属性,然后在您想要再次激活时将其替换为 href 属性。