以编程方式处理 uiwebview 中的文本字段 [英] programmatically handling a text field within a uiwebview

查看:24
本文介绍了以编程方式处理 uiwebview 中的文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有文本字段和提交按钮的网页.该网页在 UIWebView 中加载.

I have a webpage with a text field and a submit button. That webpage is loaded within a UIWebView.

我将如何以编程方式按下该网页的提交按钮?

How would I programmatically press the submit button for that webpage?

或者,我如何以编程方式使网页中的文本字段成为第一响应者并显示软键盘?只需以编程方式重新创建与用户触摸网页上的文本字段相同的行为.

Alternatively, how would I programmatically make the text field within the webpage the first responder and display the soft keyboard? Just programmatically re-create the same behavior as if the user had touched the text field on the webpage.

我想假设该页面的来源未知.

I would like to make the assumption that the source of the page is unknown.

这不是 UITextField,它只是显示在 UIWebView 中的网页内的一个.

This is not a UITextField it is just a within the webpage that is displayed in a UIWebView.

提前致谢.

推荐答案

我不确定我的问题是否清楚,但这是对我有用的答案:

I'm not sure if my question was clear, but this was the answer that worked for me:

jScriptString = [NSString stringWithFormat:@"var field = document.activeElement;" 
                     "field.value='%@';", symbol.data];
    [myWebView stringByEvaluatingJavaScriptFromString:jScriptString];
    jScriptString = [NSString stringWithFormat:@"document.activeElement.form.submit();"];
    [myWebView stringByEvaluatingJavaScriptFromString:jScriptString];

这篇关于以编程方式处理 uiwebview 中的文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆