0

我在将两个坐标从一个函数传递到另一个函数时遇到问题。我真的不知道 JavaScript,但它似乎有点正确。你能告诉我我的错误在哪里吗?

     <head>
      <script>
       var zoom = 12; // 18 for mobile phones because the geolocation is more accurate 

       function init() {
         // Don't bother if the web browser doesn't support cross-document messaging
         if (window.postMessage) {
           if (navigator && navigator.geolocation) {
             try {
               navigator.geolocation.getCurrentPosition(function(pPos) {
               send(pPos.coords.latitude, pPos.coords.longitude);
             }, function() {});
             } catch (e) {}
           } else if (google && google.gears) {
             // Relevant if targeting mobile phones (some of which may have Google Gears)
             try {
               var geoloc = google.gears.factory.create("beta.geolocation");
               geoloc.getCurrentPosition(function(pPos) {
               send(pPos.latitude, pPos.longitude);
             }, function() {});
             } catch (e) {}
           }
         }
       }

       function send(pLat, pLng) {
         var myiframe = document.getElementById("myiframe").contentWindow;
         // The third parameter, zoom, is optional
         myiframe.postMessage(pLat + "," + pLng + "," + zoom, "http://www.qib.la");
       }

       window.onload=init;
      </script>
     </head>

     <body>
      <iframe id="myiframe" src="http://www.qib.la/embed/" width="400" height="400">
        Check the prayer direction towards the Ka'ba in Makkah at
        <a href="http://www.qib.la/">Qibla Direction</a>.
      </iframe>

<script type="text/javascript" src="http://praytimes.org/code/v2/js/PrayTimes.js"></script>

<br>
<p align="center">Waterloo, ON, Canada<p>
<div align="center" id="table"></div>

<script type="text/javascript">

    var date = new Date(); // today
    var times = prayTimes.getTimes(date, pLat + "," + pLng, -5);
    var list = ['Fajr', 'Sunrise', 'Dhuhr', 'Asr', 'Maghrib', 'Isha', 'Midnight'];

    var html = '<table id="timetable">';
    html += '<tr><th colspan="2">'+ date.toLocaleDateString()+ '</th></tr>';
    for(var i in list)  {
        html += '<tr><td>'+ list[i]+ '</td>';
        html += '<td>'+ times[list[i].toLowerCase()]+ '</td></tr>';
    }
    html += '</table>';
    document.getElementById('table').innerHTML = html;

</script>


     </body>

是否可以从异步函数返回值?我如何在这里使用回调?

4

1 回答 1

0

此代码中有语法错误:

var times = prayTimes.getTimes(date, + b + ',' + c + , -5);

你有一个“+”,然后是一个逗号。我不确定您对代码的意图是什么,但这就是导致它无法运行的原因。

也许您打算遵循将逗号附加为字符串的模式?

var times = prayTimes.getTimes(date + ',' + b + ',' + c + ',' + -5);

或者也许 -5 是一个单独的论点?

var times = prayTimes.getTimes(date, b + ',' + c, -5);
于 2013-04-20T04:49:44.460 回答