UIWebView:如何在HTML文本字段中插入文本
我有一个用于加载移动网络表单网址的 UIWebView 。在我的应用程序中的一个方法中,我想在具有焦点的UIWebView的HTML文本字段中插入一些文本。
I've an UIWebView where a mobile web form URL is loaded. In a method in my application, I would like to insert some text into the HTML text field in the UIWebView which has focus.
我该如何做?有没有办法获得具有焦点的HTML元素的ID,我可以使用JavaScript将文本插入到这个元素?
How can I do that? Is there a way to get the ID of the HTML element which has focus -- than I can insert the text into this element using JavaScript?
这是一个JavaScript问题,因为我的解决方案是使用jQuery调用 $(*:focus)
更改所选元素的值在 UIWebView 中。这显然需要在 UIWebView 中加载的网页使用 jQuery 。调用是使用 -stringByEvaluatingJavaScriptFromString:
作为 Sixten Otto 描述的。
This turns out being a JavaScript question, as my solution was to use the jQuery call $("*:focus")
to change the value of the selected element in the UIWebView. This obviously requires that the page loaded in the UIWebView is using jQuery. The call was made using -stringByEvaluatingJavaScriptFromString:
as Sixten Otto describes.