Questions tagged «jquery»

jQuery是一个JavaScript库,请考虑添加JavaScript标记。jQuery是一种流行的跨浏览器JavaScript库,它通过最小化浏览器之间的差异来促进文档对象模型(DOM)遍历,事件处理,动画和AJAX交互。标记为jQuery的问题应与jQuery相关,因此问题代码应使用jQuery,并且问题中至少需要与jQuery使用相关的元素。




7
使用jQuery获取所选选项的索引
我对如何从HTML <select>项目中获取所选选项的索引有些困惑。 在此页面上,描述了两种方法。但是,两者总是在返回-1。这是我的jQuery代码: $(document).ready(function(){ $("#dropDownMenuKategorie").change(function(){ alert($("#dropDownMenuKategorie option:selected").index()); alert($("select[name='dropDownMenuKategorie'] option:selected").index()); }); }); 和在HTML (...) <select id="dropDownMenuKategorie"> <option value="gastronomie">Gastronomie</option> <option value="finanzen">Finanzen</option> <option value="lebensmittel">Lebensmittel</option> <option value="gewerbe">Gewerbe</option> <option value="shopping">Shopping</option> <option value="bildung">Bildung</option> </select> (...) 为什么会这样呢?select分配其change()方法时,是否有可能尚未“就绪” ?此外,换.index()到.val()的返回正确的值,所以这是混淆了我,甚至更多。
171 jquery  html  select  indexing 

11
jQuery .scrollTop(); +动画
单击按钮时,我将页面设置为滚动到顶部。但是首先,我使用了if语句来查看页面顶部是否未设置为0。然后,如果不是0,则设置页面动画以滚动到顶部。 var body = $("body"); var top = body.scrollTop() // Get position of the body if(top!=0) { body.animate({scrollTop:0}, '500'); } 现在,棘手的部分是在页面滚动到顶部后对某些内容进行动画处理。所以我的下一个想法是,找出页面位置。因此,我使用控制台日志来查找。 console.log(top); // the result was 365 这给了我365的结果,我想这就是我滚动到顶部之前的位置编号。 我的问题是如何将位置设置为0,以便可以添加在页面为0时运行的另一个动画? 谢谢!

18
如何在禁用按钮上启用Bootstrap工具提示?
我需要在禁用的按钮上显示工具提示,然后在启用的按钮上将其删除。目前,它的工作方式相反。 颠倒这种行为的最佳方法是什么? $('[rel=tooltip]').tooltip(); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/> <hr> <button class="btn" disabled rel="tooltip" data-title="Dieser Link führt zu Google">button disabled</button> <button class="btn" rel="tooltip" data-title="Dieser Link führt zu Google">button not disabled</button> 运行代码段隐藏结果展开摘要 这是一个演示 PS:我想保留该disabled属性。

6
jQuery添加必需的输入字段
我一直在寻找使jQuery自动使用html5验证将必需的内容写入我所有输入字段的方法,但是我很难告诉它在哪里编写它。 我要吃这个 <input type="text" name="first_name" value="" id="freeform_first_name" maxlength="150"> 并将它自动添加所需的结束标记前 <input type="text" name="first_name" value="" id="freeform_first_name" maxlength="150" required> 我以为我可以按照 $("input").attr("required", "true"); 但这是行不通的。任何帮助是极大的赞赏。

6
jQuery:同时选择元素的类和ID?
我有一些链接,我想同时选择类和ID。 这是因为我有两种不同的行为。当一类链接获得一个类名时,它们会以一种方式起作用;当同一类链接获得另一个类名时,它们将表现出不同的行为。类名通过jquery切换。 因此,我必须能够同时选择一个链接类和ID。这可能吗? 我试过了: $("a .save #country") 没有任何结果。

22
防止在jQuery中重复提交表单
我的表单需要服务器处理一些时间。我需要确保用户等待并且不会再次单击按钮来尝试重新提交表单。我尝试使用以下jQuery代码: <script type="text/javascript"> $(document).ready(function() { $("form#my_form").submit(function() { $('input').attr('disabled', 'disabled'); $('a').attr('disabled', 'disabled'); return true; }); }); </script> 当我在Firefox中尝试此操作时,所有功能都被禁用,但是该表单未与应该包含的任何POST数据一起提交。我不能使用jQuery提交表单,因为我需要将按钮与表单一起提交,因为有多个提交按钮,并且我确定POST包含哪个值使用了哪个。我需要像平常一样提交表单,并且在发生这种情况后我需要立即禁用所有内容。 谢谢!

6
向DOM添加数据属性
$('div').data('info', 1); alert($('div').data('info')); //this works $('div[data-info="1"]').text('222'); //but this don't work 我在jquery中创建元素。之后,我要添加属性“数据”。他喜欢并被添加了,但是在DOM中,这并不明显,我无法使用 $('div[data-example="example"]').html() jsfiddle

8
如何在JavaScript中设置时间延迟
我的网站上有这片js来切换图像,但是第二次单击图像时需要延迟。延迟应为1000ms。因此,您将单击img.jpg,然后将出现img_onclick.jpg。然后,您将单击img_onclick.jpg图像,然后应该有1000ms的延迟,然后才能再次显示img.jpg。 这是代码: jQuery(document).ready(function($) { $(".toggle-container").hide(); $(".trigger").toggle(function () { $(this).addClass("active"); $(".trigger").find('img').prop('src', 'http://localhost:8888/images/img_onclick.jpg'); }, function () { $(this).removeClass("active"); $(".trigger").find('img').prop('src', 'http://localhost:8888/images/img.jpg'); }); $(".trigger").click(function () { $(this).next(".toggle-container").slideToggle(); }); });
170 javascript  jquery 

13
如何在iframe上设置“ X-Frame-Options”?
如果我创建iframe这样的: var dialog = $('<div id="' + dialogId + '" align="center"><iframe id="' + frameId + '" src="' + url + '" width="100%" frameborder="0" height="'+frameHeightForIe8+'" data-ssotoken="' + token + '"></iframe></div>').dialog({ 我该如何解决错误: 拒绝显示'https://www.google.com.ua/?gws_rd=ssl'在框架中,因为它将“ X-Frame-Options”设置为“ SAMEORIGIN”。 使用JavaScript?

13
使用JQuery从Div中删除CSS
我是JQuery的新手。在我的应用程序中,我具有以下内容: $("#displayPanel div").live("click", function(){ $(this).css({'background-color' : 'pink', 'font-weight' : 'bolder'}); }); 当我单击一个Div时,该Div的颜色就会更改。在该Click函数中,我需要执行一些功能。毕竟,我想从Div中删除已应用的CSS。如何在JQuery中做到这一点?
169 jquery  css 

13
使用jQuery删除CSS“ top”和“ left”属性
我正在构建一个可拖动的地图,当拖动地图时,该元素将被赋予“ left”和“ top”属性,并且每个属性的值都这样…… <div class="map" style="top:200px; left:100px;">Map</div> 我有一个按钮,当我单击时,我想从div的内联样式中删除top和left属性,这对于jquery可能吗?
169 jquery 


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.