2012-06-29 66 views

回答

6

添加一個提交按鈕和設置其opacity0

我用這對HTML:

<form> 
    <input type="text" name="input" /> 
    <input type="submit" style="opacity:0;" /> 
</form> 

而且這alert()值:

$(document).ready(function() { 
    $("form").submit(function() { 
     alert($("[name=input]").val()); 
    }); 
}); 

你只需要處理表單的提交 - 事件,這個偉大工程與jQuery。

-2

您可以使用webview在android/iphone設備中加載html文件。

檢查以下,

  1. 資產文件夾下添加的index.html在android系統。並在mainActivity類中添加以下內容。這裏命名StackOverFlowActivity

    import android.app.Activity; 
    import android.os.Bundle; 
    import android.os.Handler; 
    import android.webkit.WebView; 
    
    public class StackOverFlowActivity extends Activity { 
    
    private Handler mHandler = new Handler(); 
    
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main); 
        WebView view=(WebView)findViewById(R.id.webView1); 
        view.getSettings().setJavaScriptEnabled(true); 
        view.loadUrl("file:///android_asset/index.html"); 
        view.addJavascriptInterface(new MyJavaScriptInterface(), "Android"); 
    } 
    
    final class MyJavaScriptInterface 
    { 
        public void ProcessJavaScript(final String scriptname, final String args) 
         {    
          mHandler.post(new Runnable() 
           { 
            public void run() 
             { 
              String h="Hi"; 
              webview.loadUrl("javascript:result(\""+h+"\")"); 
             } 
           }); 
         } 
    } 
    

    }

  2. 的index.html

    <html> 
    <head> 
    <script type="text/javascript"> 
    function clickhere()() 
    { 
        Android.ProcessJavaScript("result",null); 
    } 
    
    function result(res) 
    { 
    
        alert(res);  
    } 
    </script> 
    </head> 
    
    <body> 
    <input type="button" id="clickme" onclick="clickhere()" value="GO"></input> 
    </body> 
    </html> 
    
+3

這是一個非常酷的方式,但他正在開發一個移動網站,而不是一個應用程序;-) –

+0

我試圖將此標記爲'不是答案',因爲它與所問的問題無關,即使它會對另一個問題有所幫助。不幸的是,這個標誌是由審稿人提出的,所以我希望它可以被海報刪除。道歉! – halfer

相關問題