Worklight - jQuery mobile onclick()无效

时间:2014-06-24 12:19:58

标签: javascript html jquery-mobile ibm-mobilefirst

我正在使用 Worklight Studio 6.1 开发应用程序 我的问题是,当我点击html页面中的按钮时,它什么也没做。

以下是我的代码:

SelectPosition.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Select Position</title>
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link href="../jqueryMobile/jquery.mobile-1.4.2.min.css" rel="stylesheet">
    <link href="../jqueryMobile/jquery.mobile.theme-1.4.2.min.css" rel="stylesheet">
    <script src="../jqueryMobile/jquery.mobile-1.4.2.js"></script>
    <script src="../js/controllers/SelectPositionController.js"></script>
</head>
<body>

    <a href="#" data-role="button" id="confirmBtn" onclick="confirmClick()">Confirm</a>

</body>
</html>

SelectPositionController.js

function confirmClick() {
    alert("I am an alert box!");
}

感谢您的所有建议和解决方案。

聚苯乙烯。我的html文件位于&#34; apps / Insurance / common / views / SelectPosition.html&#34; 我的js文件位于&#34; apps / Insurance / common / js / controllers / SelectPositionController.js&#34;

[编辑]

我将所有.html文件合并到main.html文件中,一切正常。感谢您提供所有解决方案;)

2 个答案:

答案 0 :(得分:0)

如果您使用的是jquery-mobile,请避免使用html标记中的添加属性 通过jquery代码添加click事件,如

$('#control-id').on('click',function(){
      //Place code here
});

答案 1 :(得分:0)

JsFiddle: http://jsfiddle.net/66Qbx/1/

<强> HTML:

 <a href="#" data-role="button" id="confirmBtn">Confirm</a>

<强> JQuery的:

$(function() {
  $('#confirmBtn').on('click',function(){
       //Place code here
      alert("I am an alert box!");
    });
});