如何使下拉jQuery工作
How to make dropdown jQuery work?
当我测试它时,我有这个下拉菜单在jsFiddle中工作,但是当我运行它到我的测试服务器时,它不像它应该的那样工作。
jsFiddle:http://jsfiddle.net/cyberjo50/39bu8/2/
HTML<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script src="http://code.jquery.com/jquery-2.1.1.js"></script>
<script type="text/javascript" src="toggle.js"></script>
</head>
<body>
<button>Select Destinations<img src="images/down-arrow.png" width="20" height="20" alt="" style="vertical-align:middle; padding-top: 0px;"/></button>
<nav id="menu">
<a href="#">Philadelphia</a>
<a href="#">United States of America</a>
<a href="#">Philippines</a>
<a href="#">Long Destinations Names</a>
<a href="#">Some Destination</a>
<a href="#">Australia</a>
</nav>
</body>
</html>
Javascript img_arrow = '<img src="images/down-arrow.png" width="20" height="20"/>';
$(function ()
{
var $window = $(window),
$nav = $('nav'),
$button = $('button');
$button.on('click', function ()
{
$nav.slideToggle();
});
$window.on('resize', function ()
{
if ($window.width() > 320)
{
$nav.show();
}
});
});
$('#menu a').click(function(e){
$('button').html($(this).html() + img_arrow);
e.preventDefault();
});
下面是我的测试页面:http://t4fresponsivelandingpage.businesscatalyst.com/test.html 不知道为什么它不工作在我的测试页。它的工作原理应该和日本的一样。从小提琴的代码正是我在我的测试链接中使用的。
在页面加载期间而不是之后运行点击处理程序。$(function(){})
是$(document).ready()
的简写。要修复点击问题,将click
处理程序赋值移动到onDOMReady
调用内部:
$(function (){
var $window = $(window),
$nav = $('nav'),
$button = $('button');
$button.on('click', function (){
$nav.slideToggle();
});
$window.on('resize', function (){
if ($window.width() > 320){
$nav.show();
}
});
$('#menu a').click(function(e){
$('button').html($(this).html() + img_arrow);
e.preventDefault();
});
});
http://jsfiddle.net/39bu8/4/相关文章:
- 不正确的工作jquery插件bxslider与插件elevatezoom
- 更改图像src-dons't工作jquery/js
- event.prventDefault()不工作(jQuery实时)
- delay()不会'第二次工作jquery
- 如何工作 jQuery 就绪
- 几天后,昨天停止工作jQuery
- .click() 不再工作 jquery.
- 如何使工作jquery"“滑动”;在iPad上滚动
- 为什么不是't这个选择器正在工作(Jquery和Asp.net)
- Flexslider无法在html网站中工作(jQuery无法加载?)
- 点击,点击不工作?jquery
- 按钮在“加”和“减”之间切换,需要“点击”;只能在fa +上工作.jQuery
- 突出显示搜索列表不工作(jquery问题)
- 页眉内的Div /靠近页面顶部/在2次点击事件后不显示,而它的's页脚双胞胎工作- jquery
- 为什么css后台jQuery代码不工作jQuery设置多个css值
- .stop()不是't使用我的悬停,使快速移动工作-jQuery
- 自定义验证方法不工作- jQuery验证插件
- 数据表columnDefs不工作:jquery / javascript
- 工作jQuery代码赢得'不要在电话间隙跑步
- 我的Javascript代码不工作- Jquery选择器问题