javascript - 我们如何使用 find() API 来查找页面 URL 中的字符串?

标签 javascript jquery html

我有一个页面 URL,想要使用 find() API 并查找 URL 中存在的字符串。

代码:

var pageURL = document.URL;

$(pageURL).find('ArticleID');

使用上面的代码,出现错误:

need to find if the string ArticleID is present in the URL or not.

有没有比使用 find() 更好的方法?

最佳答案

Find 是一种 jQuery 方法,用于在 DOM 中查找元素,而不是在字符串中查找元素。为此,您不需要 jQuery,请使用 indexOf:

if(document.URL.indexOf("ArticleID") >= 0) {
    // ArticleID exists in document.URL
}

indexOf 返回输入字符串的第一个位置,如果未找到,则返回 -1

关于javascript - 我们如何使用 find() API 来查找页面 URL 中的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16792393/

相关文章:

javascript - JQuery 解包参数数组

jQuery UI 自动完成 : how do you start an asynchronous process and quit it before it finishes

javascript - 无法使用 jquery 删除占位符

html - like html jsp <form> 类别和子类别格式不支持

javascript - jquery 点击功能不适用于每个输入字段

javascript - 网络 AVI 播放器?

javascript - 具有相同 id 和 jQuery 的 DOM 元素

javascript - 解读 JavaScript(可能是俄语 Javascript?)

javascript - 使用这个 jquery/javascript 的奇怪的 IE 问题

html - 输入元素未显示为内联