我正在写一个网站,我想出了相当多的脚本,占用了大量的空间,破坏了代码的美观。我想出了创建一个脚本的想法,它用脚本填充下面的div,但听起来可能会出现某种问题。这是一件可以做的事,还是一种糟糕的做法?
发布于 2018-03-01 07:11:17
使用正式的约定,如require.js。例如,要加载jquery:
requirejs.config({
baseUrl: 'js/lib',
paths: {
// the left side is the module ID,
// the right side is the path to
// the jQuery UI file, relative to baseUrl.
// Also, the path should NOT include
// the '.js' file extension. This example
// is using jQuery UI located at
// js/lib/jquery-ui, relative to
// the HTML page.
jquery-ui: 'jquery-ui',
jquery-ui-autocomplete: 'jquery-ui-autocomplete'
}
});然后使用自动完成插件:
require([ "jquery-ui-autocomplete" ], function( autocomplete ) {
autocomplete({ source: [ "One", "Two", "Three" ] }, "<input>" )
.element
.appendTo( "body" );
});https://softwareengineering.stackexchange.com/questions/327584
复制相似问题