How can i add jquery to Appcelerator Titanium Mobile Work?

后端 未结 4 1300
轮回少年
轮回少年 2021-02-06 18:13

Is it possible to integrate the jquery in to Titanium Appcelerator and will it work properly? Else we can\'t integrate the jquery in titanium appcelerator?

any one help

相关标签:
4条回答
  • 2021-02-06 18:35

    you can use basically any JS library you want in a WebView. Outside of a WebView, you can use basically any JS library that does not require the DOM (like json2.js, etc.)

    (from here)

    0 讨论(0)
  • 2021-02-06 18:43

    What exactly are you trying to do? I'm not sure that it work well without the DOM

    0 讨论(0)
  • 2021-02-06 18:52

    Check out the following forum. YOu can use Jquery by removing DOM from it http://developer.appcelerator.com/question/121/use-of-jquery

    0 讨论(0)
  • 2021-02-06 18:54

    First You should create a htlm file. You should see code details below. There is jquery function. Do not forget upload jquery-1.9.min.js

    <!DOCTYPE html>
    <html class="no-js" lang="en">
    <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>Local URL</title>
    <meta name="description" content="">
    <meta name="author" content="">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <script src="jquery-1.7.1.min.js"></script>
    <script>
    
    function firedFromWebView(msg){
        $("div").html(msg);
    }
    
    //Notice that jQuery works within WebViews
    $(document).ready(function(e){
        $("a").click(function(e){
        //This will fire the custom event "fromWeb" and send the second argument
        //as the event's value
            Titanium.App.fireEvent("fromWeb",{value:"Fired from webpage"});
        });
    });
    </script>
    </head>
    <body>
        <h1>A Local Webpage</h1>
        <a href="javascript:void(0)">Touch to Fire Event</a>
        <br/>
        <div>Listening...</div>
    </body>
    </html>
    

    And Another update code blocks on app.js

    var win = Titanium.UI.createWindow({
        title:"App to Web View Interaction Through Events",
        backgroundColor:"#FFFFFF"
    });
    
    var webView = Titanium.UI.createWebView({
        url:"html/index.html"
    });
    
    var button = Titanium.UI.createButton({
        title:"Fire WebView Javascript",
        height:48,
        width:220,
        bottom:12
    });
    
    button.addEventListener("click",function(e){
        webView.evalJS("firedFromWebView('<strong>Fired!</strong>')");
    });
    
    //We can use a custom event listener to fire native code from Javascript pages
    //by using Titanium.App.addEventListener
    Titanium.App.addEventListener("fromWeb",function(e){
        //The data structure and value of e is defined in the
        //index.html page
        alert(e.value);
    });
    
    win.add(webView);
    win.add(button);
    win.open();
    
    0 讨论(0)
提交回复
热议问题