Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法仅在phonegap的第一页调用onclick事件_Android_Jquery_Cordova_Onclick - Fatal编程技术网

Android 无法仅在phonegap的第一页调用onclick事件

Android 无法仅在phonegap的第一页调用onclick事件,android,jquery,cordova,onclick,Android,Jquery,Cordova,Onclick,我正在使用cordova phonegap制作一个android应用程序。在第一页中,我尝试使用带有按钮的输入元素: $(document).ready(init()); 以及: 输入元素: <input type="button" id="task_btn" value="Button" /> 但它不起作用;但是,在第二页中,它运行良好。 元素ID定义正确 如何解决这个问题 html页面上的完整代码: <!DOCTYPE html> <html>

我正在使用cordova phonegap制作一个android应用程序。在第一页中,我尝试使用带有按钮的输入元素:

$(document).ready(init());
以及:

输入元素:

<input type="button" id="task_btn" value="Button" />
但它不起作用;但是,在第二页中,它运行良好。
元素ID定义正确

如何解决这个问题

html页面上的完整代码:

    <!DOCTYPE html>

<html>
    <head>
        <title>Home Page</title>
        <meta charset="UTF-8">
        <link rel="stylesheet" href="js/jquery.mobile-1.3.1.min.css">
        <script src="js/jquery-1.9.1.min.js"></script>
        <script src="js/jquery.mobile-1.3.1.min.js"></script>
        <script src="js/cordova.js"></script>
        <style type="text/css">
            .main {
                margin:0 auto;
                width:100%;
                height: 100%;
            }
            .button_main {
                margin-left:1%;
                width:20%;
                height: 20%;
                padding-top: 3%;
                padding-bottom: 3%;
                background-color: #fbe26f;
                float: left;
            }
            .button_right {
                margin-left: 8.75%;
                margin-right: 8.75%;
                width:20%;
                height: 20%;
                padding-top: 3%;
                padding-bottom: 3%;
                background-color: #fbe26f;
                float: left;
            }
            .p_tag {
            margin-left: auto;
            margin-top: 5%;
            margin-right: auto;
            text-align: right;
            color: #194b7e;
            width:90%;
            font: italic bold 25px/30px Georgia, serif;
            background-color: #d0d0d0;
            word-wrap: break-word;
        }
    </style>
</head>
<body>
    <div class="main" align="center">
        <div id="button_keeper" align="center">
            <input type="button" id="contact_btn" value="Contact Us" />
            <input type="button" id="product_btn" value="Product" />
            <input type="button" id="about_btn" value="About Us" />
            <!--<a href="view.html?status=1" rel="external"><div id="contact_btn" class="button_main">Contact Us</div></a>-->
            <!--<a href="view.html?status=2" rel="external"><div id="product_btn" class="button_main">Product</div></a>-->
            <!--<a href="view.html?status=3" rel="external"><div id="about_btn" class="button_main">About Us</div></a>-->
        </div>
        <p id="message" class="p_tag"></p>
    </div>
    <script type="text/javascript">
        $( document ).ready(function() {
//                $('#message').append('Device Is Ready To Use');
            document.addEventListener("deviceready", onDeviceReady, false);
        });
        function onDeviceReady() {
//                $('#message').append('<br />'+'Device Is Ready To Use');
        }
        $("#contact_btn").click(function() {
            console.log("index.html >> button clicked : ");
            $('#message').append('Contact button clicked');
        });
        $("#about_btn").click(function() {
            console.log("index.html >> button clicked : ");
            $('#message').append('About button clicked');
        });
        $("#product_btn").click(function() {
            console.log("index.html >> button clicked : ");
            $('#message').append('Products button clicked');
        });
    </script>
</body>

主页
梅因先生{
保证金:0自动;
宽度:100%;
身高:100%;
}
.主按钮{
左缘:1%;
宽度:20%;
身高:20%;
垫面:3%;
垫底:3%;
背景色:#fbe26f;
浮动:左;
}
.按钮(右){
左缘:8.75%;
右边距:8.75%;
宽度:20%;
身高:20%;
垫面:3%;
垫底:3%;
背景色:#fbe26f;
浮动:左;
}
.p_标签{
左边距:自动;
利润率最高:5%;
右边距:自动;
文本对齐:右对齐;
颜色:#194b7e;
宽度:90%;
字体:斜体粗体25px/30px格鲁吉亚,衬线;
背景色:#D0;
单词包装:打断单词;
}

$(文档).ready(函数(){ //$('#message').append('设备已准备就绪'); 文件。添加的监听器(“deviceready”,OnDeviceraddy,false); }); 函数ondevicerady(){ //$(“#消息”).append(“
”+“设备已准备好使用”); } $(“#联系电话”)。单击(函数(){ log(“index.html>>按钮点击:”); $(“#消息”).append('点击联系人按钮'); }); $(“#关于_btn”)。单击(函数(){ log(“index.html>>按钮点击:”); $(“#消息”).append('关于单击的按钮'); }); $(“#产品_btn”)。单击(函数(){ log(“index.html>>按钮点击:”); $(“#消息”).append('Products button clicked'); });
我解决了它 输入按钮更改为:

            <input type="button" id="contact_btn" value="Contact Us" onclick="contactClicked()" />
            <input type="button" id="product_btn" value="Product" onclick="contactClicked()"/>
            <input type="button" id="about_btn" value="About Us" onclick="contactClicked()"/>

感谢您的回答。

要使其与单击事件一起运行,您必须在document.ready函数中提及您的单击事件

$(document).ready(function(){

init();
$("#download_btn").click(function() {
      console.log("index.html >> task button clicked");
});
});

这将解决您的问题。

init中有什么?onDeviceReady有什么?定义“它不工作”。它不应该是
$(document).ready(init)如果您打算等待就绪处理程序?单击事件不起作用。您能显示完整代码吗?@Dato'Mohammad Nurdin,我做到了,完整代码可用我以前尝试过,对我不起作用,但我在上面添加了代码,谢谢
            <input type="button" id="contact_btn" value="Contact Us" onclick="contactClicked()" />
            <input type="button" id="product_btn" value="Product" onclick="contactClicked()"/>
            <input type="button" id="about_btn" value="About Us" onclick="contactClicked()"/>
        function contactClicked() {
            console.log("index.html >> button clicked .");
            $('#message').html('Contact button clicked');
        }
        function productClicked() {
            console.log("index.html >> button clicked : ");
            $('#message').html('Products button clicked');
        }
        function aboutClicked() {
            console.log("index.html >> button clicked : ");
            $('#message').html('About button clicked');
        }
$(document).ready(function(){

init();
$("#download_btn").click(function() {
      console.log("index.html >> task button clicked");
});
});