【问题标题】:How to check which javascript id i am viewing如何检查我正在查看的 javascript id
【发布时间】:2017-06-20 08:23:19
【问题描述】:

如果我在某个 HTML 视图中,是否可以签入 Swift 3

如果假设我在 ID 为“firstView”的第一个视图中,我想调用一个函数

let javascript = "document.getElementById('firstView')"

或者如果我在第二个视图中

let javascript = "document.getElementById('secondView')"

并根据您所在的视图执行操作?

也许我不明白 if 语句和 javascript 在 Swift 3 中是如何工作的。

【问题讨论】:

    标签: javascript html ios iphone swift


    【解决方案1】:

    如果您使用的是 WKWebView,那么答案是肯定的。这里是您需要的功能的 swift 3.0 版本文档。基本上你会在你的 webview 对象上调用这个方法,传入 javascript 检查视图 ID,然后查看完成处理程序的结果。

    /* @abstract Evaluates the given JavaScript string.
    @param javaScriptString The JavaScript string to evaluate.
    @param completionHandler A block to invoke when script evaluation completes or fails.
    @discussion The completionHandler is passed the result of the script evaluation or an error.
    */
    open func evaluateJavaScript(_ javaScriptString: String, completionHandler: ((Any?, Error?) -> Swift.Void)? = nil)
    

    【讨论】:

      猜你喜欢
      • 2014-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-01
      • 1970-01-01
      • 2015-01-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多