I have this HTML form:
<p>
<form>
<input type="text" id="result" name="Result" width="20"/>
</form>
</p>
How do I pass String value from my UITextField
in swift to that form?
Use evaluateJavaScript method like below.
class
ViewController: UIViewController {
@IBOutlet weak var oWV: WKWebView!
@IBOutlet weak var oTF: UITextField!
override func
viewDidLoad() {
super.viewDidLoad()
oWV.loadHTMLString( """
<p>
<form>
<input type="text" id="result" name="Result" width="20"/>
</form>
</p>
"""
, baseURL: nil
)
}
@IBAction func
Do( _ p: Any ) {
oWV.evaluateJavaScript(
"document.querySelector( '#result' ).value='" + ( oTF.text ?? "" ) + "'"
) { p, e in
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.