2

我在用jQM + PhoneGap嘗試我的第一個應用程序。jQuery Mobile顯示加倍按鈕

下面的代碼:

<!DOCTYPE html> 
<!-- 
     Licensed to the Apache Software Foundation (ASF) under one 
     or more contributor license agreements. See the NOTICE file 
     distributed with this work for additional information 
     regarding copyright ownership. The ASF licenses this file 
     to you under the Apache License, Version 2.0 (the 
     "License"); you may not use this file except in compliance 
     with the License. You may obtain a copy of the License at 

     http://www.apache.org/licenses/LICENSE-2.0 

     Unless required by applicable law or agreed to in writing, 
     software distributed under the License is distributed on an 
     "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
     KIND, either express or implied. See the License for the 
     specific language governing permissions and limitations 
     under the License. 
--> 
<html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    <meta name="format-detection" content="telephone=yes" /> 
    <meta id="viewport" name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" /> 
    <link rel="stylesheet" type="text/css" href="css/index.css" /> 
    <link rel="stylesheet" type="text/css" href="css/jquery.mobile-1.3.1.min.css" /> 
    <link rel="stylesheet" type="text/css" href="css/jquery.mobile.structure-1.3.1.min.css" /> 
    <link rel="stylesheet" type="text/css" href="css/jquery.mobile.theme-1.3.1.min.css" /> 
    <script type="text/javascript" src="js/jquery-2.0.0.min.js"></script> 
    <script type="text/javascript" src="js/jquery.mobile-1.3.1.min.js"></script> 
    <script type="text/javascript" src="cordova-2.7.0.js"></script> 
    <script type="text/javascript" src="js/index.js"></script> 
    <script type="text/javascript"> 
     app.initialize(); 
    </script> 
    <title>Hello World</title> 
    </head> 
    <body> 
    <div class="app" data-role="page"> 

     <div data-role="content"> 
     <a onClick="$(this).toggleClass('toggleOffButton');" data-role="button" class="toggleOnButton" id='toggleButton' data-corners="true" data-mini="false" data-theme="a" tabIndex="2"/> 
     </div> 
     <!-- /content --> 

     <div data-role="footer"> 
     Footer 
     </div> 

    </div> 
    <!-- /page --> 
    </body> 
</html> 

正如你可以看到它是一個非常簡單的頁面。

問題是,它輸出一個雙按鈕而不是一個,它讓我發瘋。

用繩子更換

<a onClick="$(this).toggleClass('toggleOffButton');" data-role="button" class="toggleOnButton" id='toggleButton' data-corners="true" data-mini="false" data-theme="a" tabIndex="2"/> 

使得打印字符串如預期只是一個時間,但該按鈕重複兩次。

關於什麼可以是問題的任何想法?

我正在讀一些關於包含兩次jQM腳本的內容,但是,正如您在代碼中看到的那樣,它們沒有被雙引用!

+0

用這個代替內嵌的JavaScript'$(文件) .on('click','#toggleButton',function(){$(this).toggleClass('toggleOnButton');});' – Omar

+0

仍然是相同的輸出 – StepTNT

+0

您是否使用自己的數據主題?雖然我不確定這是否是問題。 – Omar

回答

2

我測試了你的HTML並發現你的問題。

從標籤元素創建的jQuery Mobile按鈕必須關閉。基本上改變這種:

<a onClick="$(this).toggleClass('toggleOffButton');" data-role="button" class="toggleOnButton" id='toggleButton' data-corners="true" data-mini="false" data-theme="a" tabIndex="2"/> 

這樣:

<a onClick="$(this).toggleClass('toggleOffButton');" data-role="button" class="toggleOnButton" id='toggleButton' data-corners="true" data-mini="false" data-theme="a" tabIndex="2"/></a>  

而且給它一些文字。

而像Omar告訴你的意見,你並不需要:

<link rel="stylesheet" type="text/css" href="css/jquery.mobile-1.3.1.min.css" /> 

,如果你有這些的文件:

<link rel="stylesheet" type="text/css" href="css/jquery.mobile.structure-1.3.1.min.css" /> 
<link rel="stylesheet" type="text/css" href="css/jquery.mobile.theme-1.3.1.min.css" /> 
1

jquery mobile提供了一個很好看的自己的切換按鈕。

<label for="flip-mini">Flip switch:</label> 
<select name="flip-mini" id="flip-mini" data-role="slider" data-mini="true"> 
<option value="off">Off</option> 
<option value="on">On</option> 
</select> 

我們也可以在這裏進一步參考。 http://jquerymobile.com/demos/1.2.0/docs/forms/switch/