如何将JQuery转换为纯Javascript?

时间:2014-07-11 03:21:28

标签: javascript jquery converter

请帮助我如何将JQuery脚本转换为纯Javascript?我是这个PL的初学者。 谢谢

这是JQuery脚本:

$(document).ready(function () {
$('address').each(function () {
    var link = "<a href='http://maps.google.com/maps?q=" + encodeURIComponent( $(this).text() ) + "'  target='_blank'>" + $(this).text() + "</a>";
    $(this).html(link);
});
});

Here's the link for output of JQuery script

1 个答案:

答案 0 :(得分:2)

document.addEventListener("DOMContentLoaded", function(){
    var ele = document.querySelectorAll("address");
    for(var i = 0; i < ele.length; i++){
        var link = "<a href='http://maps.google.com/maps?q=" + encodeURIComponent( ele[i].innerText ) + "'  target='_blank'>" + ele[i].innerText + "</a>";
        ele[i].innerHTML = link;
    }
});