php 如何将类ID附加到https目标[duplicate]

vc6uscn9  于 2022-12-21  发布在  PHP
关注(0)|答案(1)|浏览(131)
    • 此问题在此处已有答案**:

(31个答案)
4天前关闭。
我需要从一个类ID附加到它,我该怎么做呢?
https://www.geonet.org.nz/earthquake/是源代码,类中的id是publicid。如果您理解我的问题,我将如何执行此操作?
<a href="www.geonet.org.nz/earthquake/ + "publicid"
我已经尝试了上述方法,但没有运气,我确实认为它不会工作,虽然。
谢谢你,如果任何人可以帮助我,这可能是一个简单的答案太

hc8w905p

hc8w905p1#

您必须在index.php和main.js中进行更改。
在index.php中,为超链接标签插入新的类“recrent”和“strong”:

...
<div class="row">
    <div class="span12 time_since invisible">
    <center><span class="hours"></span> hours <span class="minutes"></span> minutes <span class="seconds"></span> seconds since last earth quake
    </div></center>
    <div class="span6 recent_quake invisible">
        <h3>Live - Latest Quake<br>
        Magnitude: <span class="magnitude"></span> <br>Depth: <span class="depth"></span> <br> Time: <span class="origintime"></span> NZDT 24hr <br>PublicID: <a class="recent" href="" target="_blank"><span class="publicid"></span></a>
        </h3>
    </div>
    <div class="span6 strongest_quake">
        <h3>Strongest Quake Last 24 Hours<br>
        Magnitude: <span class="magnitude"></span> <br>Depth: <span class="depth"></span> <br> Time: <span class="origintime"></span> NZDT 24hr <br>PublicID: <a class="strongest" href="" target="_blank"><span class="publicid"></span></a>
        </h3>
    </div>
</div>
....

在文件main.js中,您必须在函数“checkResponse()”中添加一行,并在函数“populateStrongest(thisQuake)"中添加一行。添加的行用“// new line”标记:

function checkResponse() {
    $.ajax({
        url: url,
        crossDomain: true,
        dataType: 'json'
    }).done(function(data){
        thisQuake = data.features[0];
        if ( recentQuake != thisQuake.id ) {
            recentQuake = thisQuake.id;
            time = getTime(thisQuake.properties.origintime);
            console.log('TotalSeconds', totalSeconds);

            $('.xcoord', '.recent_quake').html(thisQuake.geometry.coordinates[0]);
            $('.ycoord', '.recent_quake').html(thisQuake.geometry.coordinates[1]);
            $('.depth', '.recent_quake').html(thisQuake.properties.depth.toFixed(0) + ' km');
            $('.publicid', '.recent_quake').html(thisQuake.properties.publicid);
            $('.origintime', '.recent_quake').html(time);
            $('.magnitude', '.recent_quake').html(thisQuake.properties.magnitude.toFixed(1));
           // new line
            $('.recent', '.recent_quake').attr("href","https://www.geonet.org.nz/earthquake/"+thisQuake.properties.publicid);

            $('.recent_quake').removeClass('invisible');
            $('.latest').removeClass('latest');
            qMap.drawOverlay({
                lat: thisQuake.geometry.coordinates[1],
                lng: thisQuake.geometry.coordinates[0],
                content: '<div data-publicid="'+thisQuake.properties.publicid+'" class="overlay latest">' + thisQuake.properties.magnitude.toFixed(1) + 'M&nbsp;' + time + '</div>'
            });

            console.log('populated again', strongestQuake);
            if ( strongestQuake.properties.magnitude < thisQuake.properties.magnitude ) {
                strongestQuake = thisQuake;
                populateStrongest(strongestQuake);
            }
        }
        totalSeconds = getSeconds(thisQuake.properties.origintime);

        $('div').find('[data-publicid="' + thisQuake.properties.publicid + '"]').twinkle({
            "effectOptions": {
                "color": "rgba(0,150, 0, 0.5)",
                "radius": 80
            }
        });
        $('div').removeClass('strongest');
        $('div[data-publicid="' + strongestQuake.properties.publicid + '"]').addClass('strongest');

        $('.strongest').twinkle({
            "effectOptions": {
                "radius": 100
            }
        });
    });
}

function populateStrongest(thisQuake) {
    time = getTime(thisQuake.properties.origintime);
    $('.xcoord', '.strongest_quake').html(thisQuake.geometry.coordinates[0]);
    $('.ycoord', '.strongest_quake').html(thisQuake.geometry.coordinates[1]);
    $('.depth', '.strongest_quake').html(thisQuake.properties.depth.toFixed(0) + ' km');
    $('.publicid', '.strongest_quake').html(thisQuake.properties.publicid);
    $('.origintime', '.strongest_quake').html(time);
    $('.magnitude', '.strongest_quake').html(thisQuake.properties.magnitude.toFixed(1));
    // new line
    $('.strongest', '.strongest_quake').attr("href","https://www.geonet.org.nz/earthquake/"+thisQuake.properties.publicid);
    $('.strongest').removeClass('strongest');
}

相关问题