javascriptでこのようなコードを書きました。
$(document).ready(function () { $(document).on("click", "input[type='file']", function () { var id = $(this).attr("id"); $("#" + id + " + label").css("background-image", ""); $(this).val(""); }); $(document).on("change", "input[type='file']", function () { var id = $(this).attr("id"); $("#" + id + " + label").css("background-image", ""); var files = !!this.files ? this.files : []; if (!files.length || !window.FileReader) { return; } if (/^image/.test(files[0].type.toLowerCase())) { var reader = new FileReader(); reader.readAsDataURL(files[0]); reader.onloadend = function () { $("#" + id + " + label").css("background-image", "url(" + this.result + ")"); }; } }); });
実行した際にこのようなエラーが出ました。
Uncaught ReferenceError: $ is not defined at main.js:147:1
サイトで調べたりしたのですが、うまくいきません。
アドバイスをいただけると嬉しいです。
回答2件
あなたの回答
tips
プレビュー