2017-01-01 53 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