问题:在使用Electron进行开发时,当您尝试使用任何需要jQuery的JS插件时,即使使用脚本标记加载正确的路径,插件也找不到jQuery.
例如,
<body>
<p id="click-me">Click me!</p>
...
<script src="node_modules/jquery/dist/jquery.min.js"></script> //jQuery should be loaded now
<script>$("#click-me").click(() => {alert("Clicked")});</script>
</body>
Run Code Online (Sandbox Code Playgroud)
运行上面的代码是行不通的.实际上,打开DevTools,转到Console视图,然后单击该<p>
元素.你应该看到那种function $ is not defined
或类似的东西.
我有这个错误消息ReferenceError: $ is not defined
这是我的标题.
<link href="css/global-style.css" rel="stylesheet" type="text/css" media="screen">
<link rel="stylesheet" type="text/css" media="screen" href="css/datepicker3.css">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="assets/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/bootstrap-datepicker.js"></script>
Run Code Online (Sandbox Code Playgroud)
以下是我的JavaScript代码
<script type="text/javascript">
$('#sandbox-container .input-daterange').datepicker({
startDate: "today",
calendarWeeks: true,
todayHighlight: true
});
</script>
Run Code Online (Sandbox Code Playgroud)
以下是HTML
<div class="col-md-12" id="sandbox-container">
<label>Project Duration</label>
<div class="input-daterange input-group" id="datepicker">
<input type="text" class="input-md form-control" name="start" />
<span class="input-group-addon">to</span>
<input type="text" class="input-md form-control" name="end" />
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我想在输入标签上显示datepicker.
我正在使用Bootstrap V3.1.
我正在使用这个日期选择器
我正在编写一段当前在tampermonkey的代码,我无法理解为什么我在谷歌浏览器的控制台中出现这个错误,"执行脚本'PalaceBOT'失败!$未定义",我有另一个脚本,使用相同的主体,我没有遇到这些问题.
脚本:
// ==UserScript==
// @name SupremeBOT
// @namespace
// @version 0.1
// @description
// @author @alfiefogg_
// @match http://www.supremenewyork.com/shop/*
// @exclude http://wwww.supremenewyork.com/shop/cart
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
// @grant none
// ==/UserScript==
var mySize = "large"; //Change to appropriate size
var productSort = "accessories"; //Change to appropriate size
(function() {
var articles = $(".product-grid-item clearfix");
if(productSort != "all"){
for(var i = 0; i < articles.length;i++)
{
var category = $(articles[i]).find("a").attr("href");
if(category.indexOf(productSort) == -1){
articles[i].remove();
document.getElementsByClassName("product-grid-item clearfix")[4].click();
}
} …
Run Code Online (Sandbox Code Playgroud) 我已经看到JavaScript库被加载在页面的顶部和底部.
我很想知道何时做出这些选择.我编写的所有JavaScript代码都在页面顶部工作,其中包括jquery插件.
我何时在任何这些位置加载我的脚本?
我正在尝试使用 AJAX 调用在我的 chrome 扩展的 Javascript 前端和我计划使用我的机器学习代码的 Flask API 之间来回发送数据。
内容.js
console.log("Application GO");
function colorChanger() {
let tweets = document.querySelectorAll("article");
tweets.forEach(function (tweet) {
$(document).ready(function () {
$.ajax({
type: "POST",
contentType: "application/json;charset=utf-8",
url: "/_api_call",
traditional: "true",
data: JSON.stringify({tweet}),
dataType: "json"
});
});
tweet.setAttribute("style", "background-color: red;");
});
}
let timer = setInterval(colorChanger, 2000);
Run Code Online (Sandbox Code Playgroud)
烧瓶代码
from flask import Flask, flash, request, redirect, url_for
from flask_cors import CORS
app = Flask(__name__)
CORS(app)
@app.route('/_api_call', methods=['GET'])
def fake_news_detector():
data = request.get_json()
with open('temp.txt', 'w') as f: …
Run Code Online (Sandbox Code Playgroud) jQuery的
<script src="http://localhost/project/public/plugins/jQuery/jquery-2.2.3.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
我的代码
<script type="text/javascript">
function readURL(input){
if(input.files && input.files[0]){
var reader = new FileReader();
reader.onload=function(e){
$('#showimages').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#inputimages").change(function(){
readURL(this);
});
</script>
<img src="" id="showimages">
<input type="file" name="images" id="inputimages">
Run Code Online (Sandbox Code Playgroud)
我得到这个错误
未被捕获的ReferenceError:在http:// localhost / project / public / user / 1 / edit:308:9中未定义$
*第308行-> $("#inputimages").change(function(){
我在js和jquery中是新手,请帮助我解决此错误...
我在该部分之外编写了脚本。这就是为什么发生错误,请参阅我的答案。
我正在使用asp.net mvc并使用Kendo UI网格控件进行数据检索,将这些功能用于另一个应用程序,而不是在代码中解决问题.所有JavaScript和Kendo网格ui参考包括当我运行应用程序时我面临这些错误
$(document).ready(function()$未定义List:178 Uncaught TypeError:$(...).kendoDatePicker不是函数
多次.当我点击错误时,他们会在这一行显示错误
<script>
$(document).ready(function () {
$("#StartDate").kendoDatePicker();
});
Run Code Online (Sandbox Code Playgroud)
我在参考文献中添加了程序集,但注意到有成效.
当我明确地在我的$(文档)之前包含jQuery库时,我无法弄清楚为什么它仍然没有识别jQuery语法.ready
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1"><title>
</title></head>
<body>
<form name="form1" method="post" action="jQueryDialogTest.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE2MTY2ODcyMjlkZA==" />
</div>
<script src="content/js/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="content/js/popup.js" type="text/javascript"></script>
<div id="testDialog" winWidth="400" winHeight="500" winResizable="true">
Some test mark-up, should show inside the dialog
</div>
<div><input type="button" id="invokeDialog" value="Click Me!" /></div>
</form>
<script type="text/javascript">
$(document).ready(function()
{
$("input.invokeDialog").click.showDialog("#testDialog");
});
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
在popup.js我有这样的例子:
function showDialog(divID)
{
// Get reference to the div element
var dialogDiv = $(divID); …
Run Code Online (Sandbox Code Playgroud) 我正在使用PHP/MySQL构建CMS,到目前为止使用jQuery为表列添加排序和过滤.通常情况下,它的伟大工程,但偶尔的排序和过滤元件将不会加载 - 如果我手动刷新页面(从来没有,如果我通过链接访问它),只是有时这只是发生.有些时候我可以在它发生之前刷新几次,而其他时候它可以连续几次发生.
问题发生时,Firebug的控制台告诉我以下一个或两个:
ReferenceError:未定义jQuery
ReferenceError:$未定义
$(document).ready(function(){
(有时候:TypeError:$(".tablesorter").tablesorter不是函数)
当一切正常加载时,控制台为空白.
我的头文件加载在CMS的所有页面上,以:
<?php ob_start(); ?>
<!DOCTYPE html>
<html>
<head>
<meta name="robots" content="noindex">
<title><?=$pg_title." - ".$site_name;?> | Lucid <?=$ver_num;?></title>
<link href="/favicon.gif" rel="icon" />
<link rel="stylesheet" href="css/styles.php" type="text/css" />
<script src="js/jquery-1.8.3.min.js" async></script>
<script src="plugins/jquery-tablesorter/js/jquery.tablesorter.min.js" async></script>
<script src="plugins/jquery-tablesorter/js/jquery.metadata.js" async></script>
<script src="plugins/jquery-tablesorter/addons/pager/jquery.tablesorter.pager.min.js" async></script>
<script src="js/picnet.table.filter.min.js" async></script>
</head>
Run Code Online (Sandbox Code Playgroud)
然后在页脚文件中,我调用各种函数:
<script async>
$(document).ready(function(){
function validateNumber(event) {
var key = window.event ? event.keyCode : event.which;
if (event.keyCode == 8 || event.keyCode == 46
|| event.keyCode == 37 …
Run Code Online (Sandbox Code Playgroud) 我是新来的AngularJS
,请帮我解决这个问题.我怎样才能调用该jQuery
函数AngularJS
.
HTML:
<div ng-controller="TestClickController">
<button ng-click="clickFunc()">Test click</button></div>
Run Code Online (Sandbox Code Playgroud)
脚本:
<script>
var app = angular.module('myApp', []);
app.controller('TestClickController', function($scope) {
$scope.clickFunc = function() {
$('#div1').html('User clicked');
};
});
</script>
Run Code Online (Sandbox Code Playgroud)
单击该按钮时,我收到错误"Error: $ is not defined"
.
jquery ×8
javascript ×7
html ×2
ajax ×1
angularjs ×1
asp.net-mvc ×1
electron ×1
flask ×1
kendo-grid ×1
laravel ×1
php ×1
python ×1
tampermonkey ×1