如何在 html 页面中调用 jquery
How to call jquery in a html page?
var currentIndex = 0,
items = $('.container div'),
itemAmt = items.length;
function cycleItems() {
var item = $('.container div').eq(currentIndex);
items.hide();
item.css('display','inline-block');
}
var autoSlide = setInterval(function() {
currentIndex += 1;
if (currentIndex > itemAmt - 1) {
currentIndex = 0;
}
cycleItems();
}, 3000);
$('.next').click(function() {
clearInterval(autoSlide);
currentIndex += 1;
if (currentIndex > itemAmt - 1) {
currentIndex = 0;
}
cycleItems();
});
$('.prev').click(function() {
clearInterval(autoSlide);
currentIndex -= 1;
if (currentIndex < 0) {
currentIndex = itemAmt - 1;
}
cycleItems();
});
这是我在另一个文件中的jquery。您知道如何从我的 html 页面包含此脚本吗?
<button class="next">Next</button>
<button class="prev">Previous</button>
<div class="container">
<div style="display: inline-block;">
<img src="http://placeimg.com/400/200/people"/>
</div>
<div>
<img src="http://placeimg.com/400/200/any"/>
</div>
<div>
<img src="http://placeimg.com/400/200/nature"/>
</div>
<div>
<img src="http://placeimg.com/400/200/architecture"/>
</div>
<div>
<img src="http://placeimg.com/400/200/animals"/>
</div>
<div>
<img src="http://placeimg.com/400/200/people"/>
</div>
<div>
<img src="http://placeimg.com/400/200/tech"/>
</div>
</div>
这是我的 html 文件,我在代码的开头包含了脚本。但似乎没有建立连接?我是这方面的初学者。谢谢
如果你想
在你的php文件中保留javascript代码,那么把它包装成<script> </script>
标签,放在php文件的末尾。
如果它是一个单独的.js
文件,则将其包含在 php 文件的末尾:<script type="text/javascript" src="Path/of/your/.js/file"> </script>
.
你可以
把所有的jquery放在.js文件中,假设你把你的jquery放在custom.js文件中:
在你的 html/php 文件中,在开头包含这个自定义.js文件:
<script type="text/javascript" src="custom.js"></script>
您可以使用 HTML 的脚本标签将整个 jquery 包含在 PHP 页面上。首先复制代码并将其放在脚本标签中。请看下面。
<script type="text/javascript">
// your jquery code //
</script>
相关文章:
- 如何在视图模型contet更新更新上调用Jquery函数
- 如何在 html 页面中调用 jquery
- 仅在小型设备上调用jQuery函数
- 未调用jquery异步函数
- 有没有一种方法可以用步骤递归调用jQuery animate()
- 调用JQuery弹出关闭按钮上的JS'X'
- 在条件内部调用JQuery函数
- ajax外部url加载完成后调用jquery函数
- 如何在几个jQuery对象上调用jQuery函数
- 在发布后调用jQuery Get
- 如何从ajax调用JQuery返回数据
- 从 document.ready 调用 jQuery 插件抛出 getPreventDefault 错误
- 从上下文中调用 JQuery 函数
- 每次调用 jQuery 函数时递增变量
- 使用 Ajax 在 html 加载后调用 jquery 插件
- 在单击按钮时调用 jquery 函数时出现问题
- 多次调用 Jquery 事件
- 从 PHP 获取当前页面 ID 后调用 jQuery 事件
- 从全局范围调用 jQuery 中的函数
- 在隐藏值上调用 jQuery .trigger('change') 会破坏与 KNOCKOUT 相关的可观察性