dtuy84033
dtuy84033
2014-10-10 10:09

在HTML页面上的javascript函数中获取嵌入值

  • php
  • html
  • javascript
  • jquery

I am using php and trying to fetch a value in a javascript function. The javascript in the HTML page is the following:

<script type="text/javascript">

        function show(q)
        {
            if(q.length > 0)
            {           
                if(q.indexOf("tid") > -1)
                {
                    location.href = "map.jsp?" + q;
                }
                else
                {
                    location.href = "listmap.jsp?" + q;
                }
            }

            return false;
        }

        $(function() { 
            $("#map").goMap({ 
                latitude: -35.331415
                ,longitude: 149.131851
                ,maptype: 'ROADMAP'
                ,scrollwheel: false
                ,zoom: 11
                ,markers: [ {latitude: -35.192103,longitude: 149.332313,icon: 'images/m/marker1.png',html: {content: 'Loading...', ajax: 'mapinfo.jsp?sid=9057'}}]

I need to get the values of (3rd and 4th lines in second function) the latitude and longitude which are: -35.331415 and 149.131851

I'm just not sure how to access the individual values...

EDIT: I AM USING PHP to save these values in variables then later write them to a csv file Currently i'm using this code (here's a snippit) to get everything else on other pages

<?php


$ch = curl_init("http://pvoutput.org/listmap.jsp?sid=312");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$cl = curl_exec($ch);


$dom = new DOMDocument();
@$dom ->loadHTML($cl);

$Lat_data = $dom -> getElementsByTagName("script");
print_r($Lat_data -> item(1) );

EDIT 2: I fixed all the problems by doing this:

$Lat_data = $dom -> getElementsByTagName("script");
$content =$Lat_data -> item(10) -> textContent;

$regex = "/latitude: ([^\b,]*)/"; 
if (preg_match( $regex , $content , $values )) {
echo  $values[1];
$regex2 = "/longitude: ([^\b,]*)/";
}
if (preg_match($regex2, $content, $values2)) {
echo $values2[1];
}
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐

换一换