0
<html>
<head><title>ABC</title>
<!--<script src="jquery.gamequery-0.7.0.js"></script>-->
<!--<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js" type="text/javascript"></script>
<style>
#abc{
    height:200px;
    width:200px;
    left: 400px;
    background: darkblue;
    position: absolute;

}
#def{
    left:  25%;
    top: 25%;
    position: absolute;
}
#ball{
    position: absolute; 
    top: 100px; 
    left: 180px;  
    line-height: 80px;
    opacity: 0;
}    

</style>
<script> 
document.addEventListener("deviceready", onDeviceReady, true); 
function onDeviceReady(){
    //set the opacity of #abc to 0(Fade)
    $("#abc").css('opacity', 0)
  //Effect Function 

  //Create fade out effect for #abc
    $("#abc").animate({ 
      top: '200px',
      opacity:'1'

    });

    //Enlarge of #def
    $("#def").animate({ 
        height: '75px',
        width: '75px'
    });

    //Blink effect for #abc
    $("#abc").effect("pulsate", { times:3 }, 100);

    //Shake effect for #def
    $( "#def" ).effect( "shake" ,{ times:3 }, 50);

    //#ball turn orbit around #abc
    var angle = 0;     // starting position (degrees)
    var distance = 100; // distance of b from a
    var speed = 300;    // revolution speed in degrees per second
    var rate  = 10;    // refresh rate in ms

    function f() {

        var o = $('#def').offset();

        var t = o.top + (distance * Math.sin(angle * Math.PI/180.0));
        var l = o.left+ (distance * Math.cos(angle * Math.PI/180.0));

        $('#ball').css({
            top: t,
            left: l
        });
        angle += (speed * (rate/1000)) % 360;
     }
    setInterval(f, rate);
    //Let the #ball to appear
    $("#ball").css('opacity',1);

};

</script> 
</head>
<body onload="onDeviceReady()">
<button id="btnTry">Try Me</button>
<button id="btnReturn" onclick="window.location.reload();">Return To Normal</button>
<div id="abc">
<img src="pix/Diamond%20Heart.gif" id="def" />
</div>
<img src="pix/Orange.gif" id="ball" />

</body>
</html>

测试.html

public class BbbMainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.bbb_main);
        WebView wv = (WebView) findViewById(R.id.webview);
        wv.getSettings().setJavaScriptEnabled(true);
        wv.loadUrl("file:///android_asset/test.html");
            }

}

BbbMainActivity.java

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    tools:context=".BbbMainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world" />
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
/>

bbb_main.xml

我对这段代码的问题是我可以在网络浏览器中正确运行代码,但是当涉及到我使用 eclipse(Android 2.1 和 Android 2.2)运行的设备模拟器时。

我能知道我犯了什么错误吗?

该代码将显示多种效果。随意将其复制到记事本中并将其保存为 .html 并运行它。

4

2 回答 2

0
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
于 2014-07-30T07:22:28.580 回答
0

尝试在 java 代码中添加 .setWebChromeClient 或 .setWebViewClient 。 http://developer.android.com/reference/android/webkit/WebView.html

public class BbbMainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.bbb_main);
        WebView wv = (WebView) findViewById(R.id.webview);
        wv.getSettings().setJavaScriptEnabled(true);
        wv.setWebChromeClient(new WebChromeClient());
        wv.loadUrl("file:///android_asset/test.html");
        }
于 2014-05-06T08:05:57.767 回答