2017-01-01 30 views
0

我希望有人能幫助我,我在onclick標籤上遇到了一些麻煩。我的所有標籤都可以在iOS設備上使用,但不能使用android我從W3Sschools代碼,這裏是我的代碼:Onclick,不能在任何Android設備上工作

<div class="col-md-6 next-slider"> 

       <ul class="tab tab-content"> 

       <li><a class="tablinks" onclick="openCity(event, 'ROOMS')">ROOMS</a></li> 
       <li><a class="tablinks" onclick="openCity(event, 'MEALS')">MEALS</a></li> 
       <li><a class="tablinks" onclick="openCity(event, 'FACILITIES')">FACILITIES</a></li> 
       <li><a class="tablinks" onclick="openCity(event, 'VISITING')">VISITING</a></li> 
       <li><a class="tablinks" onclick="openCity(event, 'SOCIAL')">SOCIAL</a></li> 
</ul> 

<div id="ROOMS" class="tabcontent"> 
    <h3>ROOMS</h3> 
    <p>All single bedrooms, most en-suite. All bedrooms are tastefully decorated and have a TV and nurse call bell. If residents wish they can bring some of their personal items and furniture.</p > 
</div> 

<div id="MEALS" class="tabcontent"> 
    <h3>MEALS</h3> 
    <p>We offer a very extensive menu of home cooked meals including popular dishes such as hotpot, shepherds pie and fish &amp; chips every Friday. Residents have a say when planning these and may take meals in their rooms when required. Special diets are catered for.</p> 
</div> 

<div id="FACILITIES" class="tabcontent"> 
    <h3>FACILITIES</h3> 
    <p>Each floor has its own large lounge and spacious dining room over-looking the Bay. Bath/shower rooms situated on all floors, easy wheelchair access throughout the building. Ground floor is Residential Care and the first, second and third floors are Nursing Care.</p> 
</div> 

<div id="VISITING" class="tabcontent"> 
    <h3>VISITING</h3> 
    <p>Relatives and friends are welcome at any time throughout the day. (We do ask that residents are not disturbed at mealtimes.) If you require any further details please do not hesitate to contact us.</p> 
</div> 

<div id="SOCIAL" class="tabcontent"> 
    <h3>SOCIAL</h3> 
    <p>There are regular activities organised by our own Social Activities Organiser, Jacqui. These include 
    Bingo, which is held twice a week and various other classes such as Painting, Music &amp; Movement, Crafts, Quizzes and Reminiscing of Past Times.</p> 
    <p>An entertainer attends The Sands once a month, singing the residents' favourite songs. 
    Pantomimes are held at Christmas time, and charity fund-raising events are held throughout the year, in which residents are welcome to get involved.</p> 
    <p><strong>Monday</strong><br> 
    Bingo 
    1.30 pm  Keswick Suite Lounge </p> 
    <p><strong>Tuesday</strong><br> 
    Word Games 
    10.15 am Grasmere Suite Lounge <br> 
    Music &amp; Movement 
    1.30pm Derwent Suite Lounge </p> 
    <p><strong>Thursday</strong><br> 
    Painting or Dominoes 
    10.15 am Keswick Suite Dining Room </p> 
    <p><strong>Friday</strong><br> 
    Reminiscence Group 
    10.15 am Keswick Suite Lounge<br> 
    Bingo 
    1.30 pm  Keswick Suite Lounge</p> 
</div> 

<script> 
    $(function() { 
    $("#tabs").tabs(); 
    }); 
</script> 

我不知道,但我有一個js文件:

// JavaScript Document 

function openCity(evt, cityName) { 
    // Declare all variables 
    var i, tabcontent, tablinks; 

    // Get all elements with class="tabcontent" and hide them 
    tabcontent = document.getElementsByClassName("tabcontent"); 
    for (i = 0; i < tabcontent.length; i++) { 
     tabcontent[i].style.display = "none"; 
    } 

    // Get all elements with class="tablinks" and remove the class "active" 
    tablinks = document.getElementsByClassName("tablinks"); 
    for (i = 0; i < tablinks.length; i++) { 
     tablinks[i].className = tablinks[i].className.replace(" active", ""); 
    } 

    // Show the current tab, and add an "active" class to the link that opened the tab 
    document.getElementById(cityName).style.display = "block"; 
    evt.currentTarget.className += " active"; 
} 

如果任何人有幫助,我將永遠感激。

親切的問候,

詹姆斯

+0

這是什麼 「事件」,你的過去嗎? 'onclick =「openCity(event,'ROOMS')」' –

+0

你測試的Android版本是什麼? – luc122c

+0

我嘗試過onclick =「(function(){openCity(event,'ROOMS');})()」但遺憾的是它不工作。它適用於每個平臺,但不適用於android。我正在使用Google Chrome和Galaxy Tab A在Android 6.0.1上進行測試。 –

回答

0

試試下面的代碼:

onclick="(function(){openCity(event, 'ROOMS');})()" 
+0

歡迎使用堆棧溢出!雖然這段代碼可能會回答這個問題,但最好包含關於問題的描述,以及代碼如何解決給定問題。對於將來,這裏是一些信息,[如何破解一個真棒回答](http://stackoverflow.com/help/how-to-answer)在堆棧溢出。 – dirtydanee

相關問題