gpt4 book ai didi

jquery - jquery startwith 选择器问题

转载 作者:太空宇宙 更新时间:2023-11-04 05:09:28 25 4
gpt4 key购买 nike

我尝试运行 jquery 但没有成功:

<script type="text/javascript">
$(function () {
var pathname = window.location.pathname;
var a = pathname.split('/');
if (a[1]^ = "login" || a[1] == "") {
$("#product").css("margin-left", "0px");
} elseif (a[1] == "admin.aspx") {
$(".pnlBreadcrumb").css("margin-left", "10px");
}
});
</script>

谁能帮助我,我哪里弄错了

谢谢

最佳答案

^ 是按位异或运算符。

  • 使用indexOf方法,返回找到的字符串的位置。
  • 使用 else if 而不是 elseif

注意:您不必在 / 处拆分 location.pathname 属性,因为路径始终以 / 开头。只需在代码中包含斜线即可。

代码:

$(function() {
var pathname = location.pathname;

if (pathname.indexOf('/login') === 0 || pathname === '/') {
$("#product").css("margin-left", "0");
} else if (pathname === "/admin.aspx") {
$(".pnlBreadcrumb").css("margin-left", "10px");
}
});

附言。这个问题是由于对 JavaScript 的理解不好造成的。我强烈建议在使用 jQuery 之前学习 JavaScript。

关于jquery - jquery startwith 选择器问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9686957/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com