【发布时间】:2015-10-22 15:36:01
【问题描述】:
我正在构建基于 Reacts 的应用程序,页面上有一些 jquery 元素,例如 JqueryUI 日期选择器和引导工具提示。
问题是这些选择在我重新加载页面之前不起作用。
所以就像 jQuery 脚本不是第一次加载一样。
我查看了控制台,没有看到任何与 jQuery/javascript 相关的错误。
任何帮助将不胜感激。这是我的 index.html 页面
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<title>ICETEA</title>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<!-- JQuery UI JS - Used for the datepicker -->
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<!-- Bootstrap theme -->
<link href="//netdna.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="/css/main.css">
<!-- JQuery UI CSS - Theme: Blitzer, used for the datepicker -->
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/themes/blitzer/jquery-ui.css">
</head>
<body>
<div id="app"></div>
<script src="/js/main.js"></script>
<script>
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
});
</script>
<script>
$(function() {
$( "#datepicker" ).datepicker();
$( "#datepicker" ).change(function() {
$( "#datepicker" ).datepicker( "option", "dateFormat", "DD d MM" );
});
});
</script>
</body>
</html>
【问题讨论】:
-
在.ready()里面设置函数
-
@Baruch - 他们是
$(function(){...})类似于$(document).ready(function(){...}) -
您需要在所有其他脚本之前加载 jQuery(现在是在 Bootstrap JS 之后)。第一 >
https://code.jquery.com/jquery-2.1.3.min.js
标签: javascript jquery html twitter-bootstrap jquery-ui