Tag: jQuery的

为什么我从jquery生成的按钮没有事件?

为什么我从jquery生成的按钮没有事件? $(‘#pop’).on(‘click’, function(){ var clone = $(‘input[id*=btn]’).clone(); $(this).after(clone); }); $(‘#btn’).on(‘click’, function(){ alert(‘clicked’); }); 小提琴

从element获取类名,并选择具有相同类的所有元素

$(‘.classToClick’).live(“click”, function () { $(this).attr(‘disabled’, ‘disabled’); $(this).val(“lol”); $.post(‘post.php’, { string: “lalala” }, function (data) { $(this).removeAttr(‘disabled’); }); }) 这段代码不起作用,因为在post中我们使用$(this) 。 当我们将其更改为.classToClick ,它可以正常工作。 我们如何才能获得点击元素的类,以便我们可以像这样使用它? $(‘.classToClick’).live(“click”, function () { var className = $(this).name; $(this).attr(‘disabled’, ‘disabled’); $(this).val(“lol”); $.post(‘post.php’, { string: “lalala” }, function (data) { $(className).removeAttr(‘disabled’); }); }) 有可能做类似的事情吗?

Jquery条件选择器

我有条件选择器的问题。 我有一些输入字段。 我想要更改具有必需属性的空字段的边框颜色。 我尝试了什么: $(“[required=’required’]”).css({ “border”: “1px solid #FF0000”, “background”: “#FFEFFF” }); $(“[required=’required’]”).blur(function () { comp(this); }); $(“[required=’required’]”).keyup(function () { comp(this); }); $(“[required=’required’]”).click(function () { comp(this); }); function comp(a) { if ($(a).val() !== “”) $(a).css({ “border”: “1px solid #ccc”, “background”: “” }); else $(a).css({ “border”: “1px solid #FF0000”, “background”: “#FFEFFF” }); } 这是一个链接: http : […]

Jquery文本滑块循环

我一直在尝试创建一个文本滑块,它会淡入并滑入,然后淡出并滑出。 然后下一个元素出现并做同样的事情。 管理得出这个。 http://jsfiddle.net/3JKkj/6/ $(document).ready(function() { $(‘#heading1’).css({opacity: 0}).animate({opacity: 1.0,left: “50px”}, 1000); $(‘#heading1’).css({opacity: 0}).delay(5000).animate({opacity: 0,left: “-50px”}, 1000); $(‘#heading2’).css({opacity: 0}).delay(7000).animate({opacity: 1.0,left: “50px”}, 1000); $(‘#heading2’).css({opacity: 0}).delay(5000).animate({opacity: 0,left: “-50px”}, 1000); $(‘#heading3’).css({opacity: 0}).delay(14000).animate({opacity: 1.0,left: “50px”}, 1000); $(‘#heading3’).css({opacity: 0}).delay(5000).animate({opacity: 0,left: “-50px”}, 1000); $(‘#heading4’).css({opacity: 0}).delay(21000).animate({opacity: 1.0,left: “50px”}, 1000); $(‘#headings4’).css({opacity: 0}).delay(5000).animate({opacity: 0,left: “-50px”}, 1000); }) 在那里有那些延迟似乎有点微不足道? 有没有更有效的方法,我怎么能循环这个,所以它不断循环。

JQuery – 为什么我得到“目标未定义”

$(document).ready(function() { $(“.menubutton”).click(function() { var $id=$(event.target.id.substring(0,2)); $(“.active”).animate({“top”: “-=1000px”}, speedanim); $(“div#homedrawer div”).filter($(“.active”)).removeClass(“active”); $(“#”+$id).animate({“top”: “+=1000px”}, speedanim); $(“#”+$id).addClass(“active”); return false; }); }); 上面的代码生成此错误“目标未定义”引用该行: var $id=$(event.target.id.substring(0,2)); 这是HTML: … 显然我的语法错了。 有什么想法吗? 谢谢

从页面内容链接到JQuery选项卡

我正在构建一个使用JQuery在主页上创建选项卡式内容的应用程序。 我正在使用这个代码示例来构建。 http://jqueryfordesigners.com/jquery-tabs/ 这一切都很好,但是如何链接到标签,以便它与在主页或网站上的任何内容中点击标签链接相同? 我的Javascript代码。 $(document).ready(function(){ var tabContainers = $(‘div.tabs > div’); $(‘div.tabs ul.tabNavigation a’).click(function () { tabContainers.hide().filter(this.hash).show(); $(‘div.tabs ul.tabNavigation a’).removeClass(‘selected’); $(this).addClass(‘selected’); return false; }).filter(‘:first’).click(); }); 我的HTML。 Tab 1 Tab 2 Tab 3 Tab 4 … … … … 我以为我可以做一些链接 My link text 在我的内容,但我假设我需要添加相同的javascript代码,使这项工作。 编辑我已经将以下代码添加到我的javascript但是我单击的选项卡没有得到选定的CSS规则。 // add code for links to tabs $(‘a.tablink’).click(function (){ tabContainers.hide().filter(this.hash).show(); […]

如何在td上修改我的工具提示

$(document).ready(function(){ var temp= // i need this to fetch the id of which td i hovered, id of the user not id //of the td so that i can put the id in the data which will be passed to description-//hover.php $(“#box-table-a span”).qtip({ content: { url: ‘description-hover.php’, data: { id: //this should be temp here […]

JQuery在单击时循环显示文本

我正在尝试创建一个jquery函数,它将更改单击时显示的文本并循环显示7个不同的段落或div。 作为一个例子,我已经创建了7个不同的div,并且希望它们像循环函数一样循环,但是在单击命令而不是定时。 这是我到目前为止: Sample text1 Sample text2 Sample text3 Sample text4 Sample text5 Sample text6 Sample text7 和JS $(document).ready(function () { var divs = $(‘div[id^=”content-“]’).hide(), i = 0; (function cycle() { divs.eq(i).fadeIn(400) .delay() .fadeOut(400, cycle); i = ++i % divs.length; })(); });

只更改包含img的li中的文本

我有这个HTML代码 criteria 1 criteria 2 我有动态更改li文本的function $(“input#criterion_name”).live(“keyup”,function(e){ var newText = $(“input#criterion_name”).val(); if(newText){ $(“ul.criteria > li.selected”).html(newText); } else{ // can’t leave the text filed empty $(“#criterion_name”).addClass(“error”); } 问题是当我在输入文本中键入文本时,li元素中的图像被删除。 我只想更改li元素中的文本

使用jQuery添加!important

我遇到了一个我无法解释的问题。 我在该函数中编写了一个函数,我在元素中添加了一些内联样式: myEm.css({“margin”:”0″, “position”:”fixed”, “top”:”50px”, “left”:”50px”}); 它工作正常,但是我注意到这个元素已经在CSS文件中设置了一些边距并且它使用了!important,所以我能够覆盖的唯一方法是将我的代码更改为 myEm.css({“margin”:”0 !important”, “position”:”fixed”, “top”:”50px”, “left”:”50px”}); 但是,当我这样做时,整个margin属性被删除。 看起来有点奇怪,但经过测试我怀疑感叹号是罪魁祸首。 我是否需要以某种方式使用编码字符来逃避它? 我错过了什么?