UIWebView與javascript互動一,uiwebview

來源:互聯網
上載者:User

UIWebView與javascript互動一,uiwebview

去年看了兩本書上面都有提到UIWebView與javascript的互動,但是很少提交具體的操作。今年時間稍微閑下來,我覺得很有必要把這個知識點整理一下。

首先一定要儲備一些簡單的javascript知識,我看的是這本電子書《javascript從入門到精通》另外還要有一些簡單的html知識的基礎。
我主要實現的功能就是載入html檔案,並操作html上的輸入框,按鈕進行操作。
test.html的代碼如下:

<html><head>    <title>test</title>    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>     <script type ="text/javascript" src ="test.js"></script></head><body>    <form name="myform">        <table>            <tr>                <td height ="30" width ="320" align="center" bgcolor="#DC143C">I'm Jack,I'm an IOS coder</td>            </tr>            <tr>                <td height ="30" width ="320" align="center">                    <input name ="input1" id ="input1" type="text" size="25" maxlength="100" >                </td>            </tr>            <tr>            </tr>            <tr>            </tr>            <tr>                <td height="30" width="60" align="center">                    <input name ="submit" type="submit" value="submit" onClick ="check()">                </td>            </tr>        </table>    </form></body></html>

test.js 的代碼如下:

function check(){    var str = document.getElementById('input1').value    alert(str);}

OC的代碼在這裡就不貼出來了,相信大家做IOS的差不多都能搞定,UIwebview 中html檔案的載入大家都可以搞的定。
下面就跟大家分享下運行效果:


可以看到這裡只是對頁面上的事件進行響應,但是比如擷取輸入的內容,這一塊,還沒有實現,將在下篇文章中和大家分享。
demo

我這裡也是剛剛開始學習,希望能和大家多多交流哦,如果能有高手給指教下更好了。^_*

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.