我在谷歌CDN 的官方文档中读到这是srcjQuery:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
但是,src在每个版本更新时必须更改我的jQuery 引用是很烦人的.
我发现,如果我将版本设置为,1则Google会返回最新版本的jQuery.
http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
/*! jQuery v1.8.2 jquery.com | jquery.org/license */
Run Code Online (Sandbox Code Playgroud)
这是正确的做法吗?是否有任何官方URL可以引用Google CDN上托管的最新版jQuery?
我得到了这段代码放在我的html页面中,但我对javascript一无所知,所以我不知道在哪里放置它以及放置它的标签类型.
$('input[type=radio]').change(function() {
$('input[type=radio]').each(function(index) {
$(this).closest('tr').removeClass('selected');
});
$(this).closest('tr').addClass('selected');
});
Run Code Online (Sandbox Code Playgroud) 如何通过在aspx页面中使用jquery/JavaScript函数将焦点设置在asp:TextBox中,该文件放在用户控件中?
我正在使用Wordpress开发网站,我想使用lates版本的jQuery.
为了确保我使用lates版本,我从Binary Bonsai的例子中找到了这段代码.
我看到的是,他实际上是在Google API上链接到jQuery.
所以我的问题是,什么是更好的.
要链接到外部页面上的jQuery吗?
http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js
或者在本地使用jquery文件?
wp_enqueue_script('jquery', '/js/jquery-1.4.2.min.js');
UPDATE
感谢Colin,答案实际上就在这里:
为什么我要将Google的CDN用于jQuery?
但是,如果你没有Google像我这样的搜索词,我会复制John Gietzen的答案
它增加了可用的并行性.
(大多数浏览器一次只能从任何给定的站点下载3或4个文件)
它增加了缓存命中的可能性.
(随着越来越多的网站遵循这种做法,更多用户已准备好该文件.)
它确保有效载荷尽可能小.
(谷歌可以预先压缩文件,使下载时间非常短.)
它减少了服务器使用的带宽量.
(谷歌基本上提供免费带宽.)
它确保用户获得地理上接近的响应.
(谷歌在世界各地都有服务器,进一步减少了延迟.)
谷歌加载器
<script type="text/javascript">
google.load('jquery','1.7.1');
google.load('jqueryui','1.8.17');
</script>
Run Code Online (Sandbox Code Playgroud)
要么...
标准的<script>标签
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
哪个更好?为什么?
我试图在用户点击td内部的任何元素时发出一个点击事件tbody.这是我到目前为止所得到的,但它没有提出事件,任何想法为什么?
<head runat="server">
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
$("#skuOptionsBody td").click(function () {
alert('clicked!');
});
</script>
</head>
<body>
<form id="form1" runat="server">
<table id="options" border="1">
<thead>
<tr>
<td>
SWEET OPTION
</td>
<td>
DRINK OPTION
</td>
</tr>
</thead>
<tbody id="skuOptionsBody">
<tr>
<td style="text-align: center">
SO1
</td>
<td style="text-align: center">
DO1
</td>
</tr>
</tbody>
</table>
</form>
</body>
Run Code Online (Sandbox Code Playgroud)
更新:
对不起,我忘了提到我使用jQuery动态地向表添加行,因为我正在添加新行,我需要它们绑定到这个click事件.如何做到这一点?
我曾经在我的网站上有一个工作日期时间选择器,但现在它已经停止工作了.我发现我引用的js被删除了.我去了页面并下载了js并将其本地存储在我的服务器上.
这是我从哪里获得js:
http://trentrichardson.com/examples/timepicker/
我在datetimepicker之前导入jquery和jquery ui:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
Uncaught TypeError: Object [object Object] has no method 'prop' datetimepicker.js:387
Run Code Online (Sandbox Code Playgroud)
这个方法应该来自jquery-ui吗?我该如何解决这个问题?
我尝试在我的网站上使用jQuery,但它似乎没有用.我认为我做错了什么,所以我尝试将我完成的codecademy课程复制到测试网站上.这是代码:
HTML
<!DOCTYPE html>
<html>
<head>
<title>Test Codecademy Lesson</title>
<link rel='stylesheet' type='text/css' href='stylesheet.css'/>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type='text/javascript' src='script.js'></script>
</head>
<body>
<img src="http://i1061.photobucket.com/albums/t480/ericqweinstein/elevator.png"/>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
CSS
body {
margin: 0;
padding: 0;
}
img {
position: absolute;
}
Run Code Online (Sandbox Code Playgroud)
使用Javascript/jQuery的
$(document).ready(function() {
$('img').animate({top:'+=100px'},1000)
});
Run Code Online (Sandbox Code Playgroud)
有人能告诉我为什么这段代码不起作用?我的浏览器是Chrome,我有最新版本.
jquery ×7
javascript ×5
html ×3
google-cdn ×2
asp.net ×1
cdn ×1
css ×1
google-api ×1
php ×1
textbox ×1
wordpress ×1