V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
iamjjh
V2EX  ›  iDev

请问 IOS 中有什么方法获取 webView 中用户输入的文字吗

  •  
  •   iamjjh · 2015-12-22 17:27:52 +08:00 · 3927 次点击
    这是一个创建于 3045 天前的主题,其中的信息可能已经有所发展或是发生改变。

    今天有个需求是在 app 中获取 webview 里用户在输入框中输入的文字,请问有什么实现方式或者思路吗?求教

    9 条回复    2015-12-23 09:29:13 +08:00
    superleexpert
        1
    superleexpert  
       2015-12-22 17:31:27 +08:00
    通过 WEB 端 JS 回调来传递输入的信息。
    vincentxue
        2
    vincentxue  
       2015-12-22 17:45:33 +08:00
    一般 input 都设了 name 或者 id 吧,调 JS 就行.

    document.getElementById('id').value

    id 是你 HTML 里 textField 的 id.

    没测试过,理论上应该是可行的。
    chengkai1853
        3
    chengkai1853  
       2015-12-22 17:54:04 +08:00
    1 楼正解
    qiayue
        4
    qiayue  
       2015-12-22 17:59:55 +08:00
    iOS 的话,你可以直接注册一个 js 函数(假设叫 getName ), js 中用 nativ.getName() 可以调用你的函数
    Keita1314
        5
    Keita1314  
       2015-12-22 18:03:24 +08:00
    javascript:document.getElementById('id').value
    OC:UIWebView stringByEvaluatingJavaScriptFromString
    iamjjh
        6
    iamjjh  
    OP
       2015-12-22 18:41:23 +08:00
    em70
        7
    em70  
       2015-12-22 19:37:12 +08:00 via iPhone
    对网页有控制权吗?有就好办,点击按键把输入框内容做成 url 发出一个 http 请求, webbview 拦截请求获得 url 从中分析出输入内容即可,非常稳定
    iamjjh
        8
    iamjjh  
    OP
       2015-12-23 09:00:22 +08:00
    @em70 多谢指教
    NUT
        9
    NUT  
       2015-12-23 09:29:13 +08:00
    @em70 这个方法好,内容直接 base64 吗?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5347 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 08:29 · PVG 16:29 · LAX 01:29 · JFK 04:29
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.