0
どのように他のjavascriptにjavascriptファイルを含めることができますか?javascriptファイルの使用方法
フロントエンドのJavaScriptです。
私はHTMLに含めたくない、私はnodeJSのようにしたい:
var jquery = require("jquery.js");
jquery.$("#c").style.color = "green";
私はこの試みた:
const jqLink = 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js';
/* I try this, what give me a error, with requireJS */
define([jqLink], function(jq){
return jq;
});
jq$("#c").style.color = "red";
<html><head><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.5/require.js"></script>
</head>
<body><h1 id="h1tag">Im h1tag</h1>
</body>
PDを:私はこれを試してみましたtoo
Main.js:
window.addEventListener("DOMContentLoaded",main);
function main(){
scripts();
var e = new ES();
e.get("#ti").style.opacity = +true;
}
function scripts(){
var list = ["es.js"], script = document.createElement("script"),b = document.head, i=0,max = list.length;
for(;i<max;i++){
script.src = list[i];
b.appendChild(script);
}
}
ES.JS:
class ES{
constructor(){
}
get(symbol, e){
let d = document;
return symbol === "#" ? d.getElementById(e) : symbol === "." ? d.getElementsByClassName(e) : d.getElementsByTagName(e);
}
}
そんなにクライアント側 –
に同期インポートできませんの...?ジョナスW. –