gpt4 book ai didi

javascript - 根据内容查找登录表单

转载 作者:行者123 更新时间:2023-11-28 16:19:52 26 4
gpt4 key购买 nike

基本上,当 HTML 文档上有多个表单时,我想找出登录表单。我的猜测如下:如果我可以识别 '忘记密码''记住我''保持登录状态' 等表单字符串会怎样? 属于,那么它可能是登录表单,因为此类字符串/链接出现在密码字段之后。

有什么方法可以找出哪个表单包含这些字符串/链接,然后在我的应用程序中使用该表单的名称或 ID?

更新:我使用以下代码来获取包含字符串“忘记密码”的表单 ID,但它什么也不返回。

NSString *formID = [NSString stringWithFormat:@"%@",[self.browser stringByEvaluatingJavaScriptFromString:@"$('form').filter (function() {var text = this.innerHTML.toLowerCase();" 
"return text.indexOf('forgot your password') != -1 || "
"text.indexOf('remember me') != -1;}).attr('id');"] ];

最佳答案

var loginFormId = $('form').filter(function() {
return this.innerHTML.indexOf('forgot your password') != -1;
}).attr('id');​

或者简单地使用 :contains:

var loginFormId = $('form:contains("forgot your password")').attr('id');​

:包含选择器docs :

Description: Select all elements that contain the specified text. The matching text can appear directly within the selected element, in any of that element's descendants, or a combination thereof. As with attribute value selectors, text inside the parentheses of :contains() can be written as a bare word or surrounded by quotation marks. The text must have matching case to be selected.

LIVE DEMO

<小时/>

更新:

如果您不确定文本的大小写,则必须使用过滤器:

var theFormId = $('form').filter(function() {
var text = this.innerHTML.toLowerCase();
return text.indexOf('forgot your password') != -1 ||
text.indexOf('remember me') != -1;

关于javascript - 根据内容查找登录表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10069564/

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