Tag: 点击

jquery初学者:点击后更改背景

我正在尝试根据当前颜色更改单击元素的背景。 这是相关的html: 和我的jquery尝试: $(“#rect”).click(function() { if ($(this).css(‘background’) == ‘red’) { $(this).css(‘background’,’blue’);} else {$(this).css(‘background’,’yellow’);} }); 我总是得到一个黄色的盒子; ‘真实’的条件永远不会发生。 我究竟做错了什么?

jQuery:在动画期间禁用点击

所以我正在进行一个小测验,我希望在动画运行时禁用#qWrap内部的所有内容,从而防止垃圾邮件点击。 我尝试使用.is(‘:animated’)但没有效果。 有任何想法吗? HTML: What are italics? Slanted cut of a type A group of italian-designed typefaces An other word for the !-sign Who designed Comic Sans? Mathew Carter David Carson Vincent Connare What does Helvetica mean? From Austria From Germany From Switzerland JS: $(‘.qAnswers li a’).bind(‘click’, function(event) { $(this).parent().addClass(‘selected’); $(this).closest(‘.qAnswers’).find(“li:not(.selected, .qQuestion)”).delay(200).addClass(‘notSelected’); var $anchor = […]

从hover切换到点击?

我最近在我的网站上在页面底部实现了一个小盒子,当鼠标hover在它上面时进行扩展…这是代码,一切都很好。 CSS #box{ position:absolute; width:300px; height:20px; left: 33%; right: 33%; min-width: 32%; bottom:0; background-color: #353535; } JavaScript的 $(‘#box’).hover(function() { $(this).animate({ height: ‘220px’ }, 150); },function() { $(this).animate({ height: ’20px’ }, 500); }); 但是我很好奇我是如何改变它来打开和关闭点击而不是鼠标hover在它上面? 我把它编辑成…… $(‘#box’).click(function() { $(this).animate({ height: ‘220px’ }, 150); },function() { $(this).animate({ height: ’20px’ }, 500); }); 这可以打开盒子。 但我无法通过另一次点击再次关闭它。 到目前为止如此接近! :P

使用jQuery在按键后触发按钮单击事件

我有这些代码 $(‘#search-button’).keypress(function (e) { if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) { search(); }; }); $(‘#search-button’).bind(‘click’, function () { search(); }); 在搜索模块下我有一个警告,现在每当按下按钮时按Enter键,click事件下的search()也会触发。 请帮忙。 谢谢。

当overlay设置为null时,使用外部单击关闭fancybox

我正在使用fancybox 2.1.4插件。 它运作完美,但我有一个问题。 我想将叠加设置为null,我想在用户点击外部(!)fancybox容器时关闭fancybox。 我尝试了以下代码,但它无法正常工作,因为没有可以单击的叠加层。 $(“.fancy_gallery”).fancybox.({ loop:false, padding:0, helpers:{ overlay:null, closeClick:true } }); 那么,当我点击外面时,我怎么能强制关闭fancybox呢? 因为,现在我必须单击关闭按钮才能关闭它。

打开Fancybox弹出窗口时添加按钮单击事件

当我使用以下代码加载我的Fancybox弹出窗口时,我正在尝试向按钮标记添加按钮onclick事件: var processOrder = function(id) { $(‘#processPopupLink’).fancybox({ ‘hideOnContentClick’: false, ‘frameWidth’: 850, ‘frameHeight’: 695 }).click(); $(‘#processComplete’).click(function() { alert(‘debug’); }); } 但是,当我点击按钮时,它没有显示消息框,我不知道为什么它不起作用,任何帮助将不胜感激。 编辑 我不想让它点击按钮,我希望它能够在打开fancybox弹出窗口时为fancybox弹出窗口上的现有按钮添加onclick。

img缩略图单击用缩略图标题替换div文本值

JSFIDDLE在这里 如果你看一下js小提琴,你会发现点击缩略图改变了图像以及.currentimgtitle文本值,但它改变了页面上所有.currentimgtitle文本值,当我只想更改与jquery和html相关的那个时。下面 $(“.imgcontainer”).each(function() { var imgsrc = $(“.minicontainer img:first-child”, this).attr(“src”); var imgtitle = $(“.minicontainer img:first-child”, this).attr(“title”); $(this).append(” + imgtitle + ”); }); $(“.miniimg, .miniimg2, .miniimg3”).click(function() { var miniimgrc = $(this).attr(“src”), $presentImg = $(this).closest(“.imgcontainer”).find(“.presentimg”); $presentImg.attr(‘src’, miniimgrc); }); $(“.miniimg, .miniimg2, .miniimg3”).click(function(index) { var miniimgtitle = $(this).attr(“title”), $presentTitle = $(this).closest(“.imgcontainer”).find(“.currentimgtitle”); $presentTitle.attr(‘title’, miniimgtitle); }); $(“.imgcontainer”).each(function(index) { $(“.miniimg, .miniimg2, .miniimg3”).click(function() […]

jquery翻转和活动状态

我为任何愚蠢的问题/编码道歉,我对jquery很新! 我正在尝试为具有翻转和活动状态的单页网站创建菜单。 HTML: jQuery的: $(document).ready(function(){ $(“a.rollover”).fadeTo(1,0.5); $(“a.rollover”).hover( function() {$(this).fadeTo(“fast”,1);}, function() {$(this).fadeTo(“fast”,0.5);}); $(“a.rollover”).click(function(){ if($(“.active”).length) { if($(this).hasClass(“active”)) { $(this).removeClass(“active”); $(this).fadeTo(“fast”,0.5); } else { $(“.active”).fadeTo(“fast”,0.5); $(“.active”).removeClass(“active”); $(this).addClass(“active”); $(this).fadeTo(“fast”,1); } } else { $(this).addClass(“active”); $(this).fadeTo(“fast”,1); }}); }); 所以这里有两个问题: 即使添加了活动类,并且在Chrome的开发人员工具中,我可以看到活动类的不透明度为“1”,它似乎在浏览器中不起作用,即。 不透明度仍然在浏览器中显示为“0.5”。 如果$(this)处于活动状态,即使单击$(this)从而删除活动类,不透明度仍为“1”。 如果我多次点击$(this),最终不透明度会变回“0.5”。 我非常感谢你的帮助。 我一直在努力争取这个……现在3天嘿: – / 提前谢谢了…

jQuery:在新选项卡/窗口中打开链接时,不会调用click处理程序

我注意到当用户点击链接时,例如中间按钮或shift / ctrl +左按钮,不会调用附加到超链接的单击处理程序。 我已经看到了跟踪mousedown事件的解决方案,但我想要的是跟踪链接的确切事件。 有什么建议吗? 谢谢

几秒后,角度引导弹出隐藏

这是我的HTML代码: 单击该图标时,将按预期打开弹出窗口。 只需单击图标即可关闭弹出窗口。 我希望在几秒钟后自动关闭popover。 这是我的javascript代码 – 不起作用: $(‘.pop’).popover().click(function () { setTimeout(function () { $(‘.pop’).popover(‘hide’); }, 4000); }); 跑步的时候 $(‘.pop’).popover() 在FF调试器上我得到: typeError: undefined is not a function 请帮忙 :)