2017-05-04 66 views
0

假設我在Swift中的UIWebview中包含了Web應用程序。我怎樣才能檢索輸入欄,隱藏或鍵入類似下面如何使用Swift和Kanna庫獲取HTML表單值

<input type="text" name="code" value="Swift"> 

用斯威夫特和看那

這裏是我得到一個H2標籤工作正常碼的值。但我需要獲得輸入字段,特別是隱藏字段。

func parseHtml(html: String) { 
    if let doc = Kanna.HTML(html: html, encoding: String.Encoding.utf8) { 
     for node in doc.css("h2") { 
      let value = node.text!.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) 
      print("\(value)") 
     } 
    } 
} 

回答

0

如果添加一個id您輸入的標籤,你可以隨時在你的UIWebView中運行JavaScript函數 檢索值。

<input type="text" id= "codeId" name="code" value="Swift"> 

var inputValue = webView.stringByEvaluatingJavaScriptFromString("document.getElementById('codeId').value")! 
相關問題