如何将jquery转换为普通的java脚本

时间:2015-08-14 10:51:10

标签: javascript jquery

不好意思,有人可以帮我把这段代码翻译成普通的JS(如果有可能的话)??

$(function() {
    $('#nav-accordion').dcAccordion({
        eventType: 'click',
        autoClose: true,
        saveState: true,
        disableLink: true,
        speed: 'slow',
        showCount: false,
        autoExpand: true,
//        cookie: 'dcjq-accordion-1',
        classExpand: 'dcjq-current-parent'
    });
});

1 个答案:

答案 0 :(得分:2)

您需要将dcAccordion插件中的所有代码翻译为本机JavaScript。不是一件容易的事。对于$(function () {}),您可以执行以下操作:

window.ondomready = function () {

};

ondomready概念太大了,对于预告片,请看这个答案:pure JavaScript equivalent to jQuery's $.ready() how to call a function when the page/dom is ready for it

简而言之,它说:

document.addEventListener('DOMContentLoaded', fn, false);
window.addEventListener('load', fn, false );
document.attachEvent("onreadystatechange", fn);
window.attachEvent("onload", fn);