关于 JQuery 条件语句的帮助
我试图在特定页面上运行一些 JQuery 脚本,但前提是加载特定页面。
场景:我们有一个加载页面(即,webpage.aspx),它根据引用点击加载不同的内容。 (即,webpage.aspx?contentId=1、webpage.aspx?contentId=2、webpage.aspx?contentId=3 等)。这是我的问题。如果只提取一个特定的 contentId,我需要删除页面的特定部分。我正在尝试在 JQuery 中执行此操作,但似乎无法弄清楚。
这是我迄今为止一直在做的事情。我意识到这是不正确的,但希望它能为您提供一个工作的起点。
谢谢。
代码:
$(window).load(function() {
var $deleteNewRow = $("div.col.w140 tbody:first").find("td:first").parent().remove();
if($('#dealer-info h1').indexOf('Ferrari') != -1) {
$deleteNewRow
}
});
I am trying to run some JQuery script on a particular page but only if a certain page loads.
The Scenario: We have one page that loads (i.e., webpage.aspx) and it loads different content based on the referring click. (i.e., webpage.aspx?contentId=1, webpage.aspx?contentId=2, webpage.aspx?contentId=3, etc). Here is my problem. I need to have a particular part of the page removed if only one specific contentId is pulled. I am trying to do this in JQuery and can't seem to figure it out.
Here's what i have been working with so far. I realize it's not correct but hopefully it gives you a starting point to work with.
Thanks.
CODE:
$(window).load(function() {
var $deleteNewRow = $("div.col.w140 tbody:first").find("td:first").parent().remove();
if($('#dealer-info h1').indexOf('Ferrari') != -1) {
$deleteNewRow
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 jQuery
:contains
选择器来检查是否存在。这是文档。然后要删除找到该元素,然后使用
remove
。You can use jQuery
:contains
selector to check for the existence. Here is the docs.Then to delete find the element and then use
remove
.您存储在
$deleteNewRow
变量中的不是 jQuery 方法,该方法已经执行。您想在 if 语句中执行该方法,如下所示(请注意,您还缺少 if 语句中的.text()
):What you store in your
$deleteNewRow
variable isn't the jQuery method, that method will already execute. You want to do that method in your if statement, something like this (note that you are also missing the.text()
in the if statement):