Questions tagged «jquery»

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

7
我可以将哪些属性与event.target一起使用?
我需要确定触发事件的元素。 使用event.target获取相应的元素。 我可以从那里使用哪些属性? href ID nodeName 即使在jQuery页面上,我也找不到很多信息,因此希望有人可以完成上面的列表。 编辑: 这些可能会有所帮助:selfHTML节点属性和selfHTML HTML属性


12
TypeError:$(…).DataTable不是函数
我正在尝试通过此链接为我的项目使用jQuery的Datatable JS 。 我从同一来源下载了完整的库。软件包中给出的所有示例似乎都可以正常工作,但是当我尝试将其合并到我WebForms的CSS,JS中时,它们根本无法工作。 这是我所做的: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <link href="css/jquery.dataTables.css" rel="stylesheet" type="text/css" /> </head> <body> <form id="form1" runat="server"> <div> <table id="myTable" class="display" cellspacing="0" width="100%"> <thead> <tr> <th>Name</th> <th>Position</th> <th>Office</th> <th>Age</th> <th>Start date</th> <th>Salary</th> </tr> </thead> <tfoot> <tr> <th>Name</th> <th>Position</th> <th>Office</th> <th>Age</th> <th>Start date</th> <th>Salary</th> </tr> </tfoot> <tbody> <!-- …

26
使用AJAX加载Bootstrap弹出内容。这可能吗?
我尝试过的适当位置在这里: <a href="#" data-content="<div id='my_popover'></div>"> Click here </a> $(".button").popover({html: true}) $(".button").click(function(){ $(this).popover('show'); $("#my_popover").load('my_stuff') }) 单击后,我看到请求已发出,但没有填充弹出窗口。我什至看不到将弹出式窗口的HTML添加到DOM中,但这可能是萤火虫。 有人尝试过吗?

6
javascript jquery单选按钮单击
我有2个单选按钮和jquery正在运行。 <input type="radio" name="lom" value="1" checked> first <input type="radio" name="lom" value="2"> second 现在,使用按钮,我可以将onClick设置为运行功能。单击单选按钮时,使单选按钮运行功能的方式是什么?

6
删除除一个以外的所有类
好吧,我知道,通过一些jQuery动作,我们可以为特定的div添加很多类: <div class="cleanstate"></div> 假设通过点击和其他操作,div获得了很多类 <div class="cleanstate bgred paddingleft allcaptions ..."></div> 那么,如何删除除一个类之外的所有类?我提出的唯一想法是: $('#container div.cleanstate').removeClass().addClass('cleanstate'); 虽然removeClass()杀死所有类,但div搞砸了,但是在此之后添加addClass('cleanstate')它又恢复了正常。另一种解决方案是将ID属性与基本CSS属性放在一起,这样它们就不会被删除,这也可以提高性能,但是我只想知道另一种解决方案,以摆脱“ .cleanstate”之外的所有问题。 我之所以这样问是因为,在实际的脚本中,div遭受了类的各种更改。

10
按文字选择链接(完全匹配)
使用jQuery,我想选择一个完全包含某种文本的链接。例如: <p><a>This One</a></p> <p><a>"This One?"</a></p> <p><a>Unlikely</a></p> 我已经试过了: $('a:contains("This One")') 但是它选择了第一个和第二个链接。我只想要第一个链接,其中确切包含“这个”。我怎样才能做到这一点?

8
jQuery按值选择选项元素
我有一个由span元素包裹的select元素。我不允许使用选择ID,但可以使用跨度ID。我正在尝试编写一个javascript / jquery函数,其中输入为数字i,这是select选项的值之一。该功能会将相关选项变为选中状态。 <span id="span_id"> <select id="h273yrjdfhgsfyiruwyiywer" multiple="multiple"> <option value="1">cleaning</option> <option value="2">food-2</option> <option value="3">toilet</option> <option value="4">baby</option> <option value="6">knick-knacks</option> <option value="9">junk-2</option> <option value="10">cosmetics</option> </select> </span> 我写了一些东西(这不能完全起作用,这就是为什么我要发布这个问题): function select_option(i) { options = $('#span_id').children('select').children('option'); //alert(options.length); //7 //alert(options[0]); //[object HTMLOptionElement] //alert(options[0].val()); //not a jquery element //alert(options[0].value); //1 //the following does not seem to work …

8
在jQuery UI自动完成功能上未检测到任何结果
是的,在您向我指出这些问题之前,我已经审查了有关该主题的六篇文章,但是我仍然对为什么这行不通感到困惑。 我的目标是检测自动填充何时产生0个结果。这是代码: $.ajax({ url:'sample_list.foo2', type: 'get', success: function(data, textStatus, XMLHttpRequest) { var suggestions=data.split(","); $("#entitySearch").autocomplete({ source: suggestions, minLength: 3, select: function(e, ui) { entityAdd(ui.item.value); }, open: function(e, ui) { console.log($(".ui-autocomplete li").size()); }, search: function(e,ui) { console.log("search returned: " + $(".ui-autocomplete li").size()); }, close: function(e,ui) { console.log("on close" + $(".ui-autocomplete li").size()); $("#entitySearch").val(""); …

2
jQuery xml错误'请求的资源上没有'Access-Control-Allow-Origin'标头。
我正在从事我的这个个人项目,只是出于娱乐目的,我想阅读位于http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml的xml文件, 并解析xml和用它在货币之间转换价值。 到目前为止,我想出了下面的代码,该代码是基本的,可以读取xml,但是出现以下错误。 XMLHttpRequest无法加载****。所请求的资源上没有“ Access-Control-Allow-Origin”标头。因此,不允许访问原始站点“ http://run.jsbin.com ”。 $(document).ready( function() { $.ajax({ type: 'GET', url: 'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml', dataType: 'xml', success: function(xml){ alert('aaa'); } }); } ); 我没有发现我的代码有什么问题,所以我希望有人可以指出我的代码有什么问题以及如何解决。

7
Rails无法从jQuery正确解码JSON(数组变成带有整数键的哈希)
每当我想用jQuery将JSON对象数组发布到Rails时,都会遇到这个问题。如果我对数组进行字符串化,我可以看到jQuery在正确执行其工作: "shared_items"=>"[{\"entity_id\":\"253\",\"position\":1},{\"entity_id\":\"823\",\"position\":2}]" 但是,如果我只是将数组作为AJAX调用的数据发送,则会得到: "shared_items"=>{"0"=>{"entity_id"=>"253", "position"=>"1"}, "1"=>{"entity_id"=>"823", "position"=>"2"}} 而如果我只是发送一个简单的数组,它将起作用: "shared_items"=>["entity_253"] Rails为什么将数组更改为该奇怪的哈希?我想到的唯一原因是,Rails无法正确理解内容,因为这里没有类型(是否可以在jQuery调用中设置它?): Processing by SharedListsController#create as 谢谢! 更新: 我将数据作为数组而不是字符串发送,并且使用该.push()函数动态创建了数组。尝试使用$.post和$.ajax,结果相同。

7
我想了解jQuery插件语法
jQuery网站列出了jQuery的基本插件语法,如下所示: (function( $ ){ $.fn.myPlugin = function() { // there's no need to do $(this) because // "this" is already a jquery object // $(this) would be the same as $($('#element')); this.fadeIn('normal', function(){ // the this keyword is a DOM element }); }; })( jQuery ); 我只是想从Javascript的角度了解发生了什么,因为它看起来不符合我以前见过的JS语法。所以这是我的问题清单: 如果将function($)...替换为变量,说“ the_function”,则语法如下所示: (the_function)( …

7
jQuery ajax(jsonp)会忽略超时,并且不会触发错误事件
为了添加一些基本的错误处理,我想重写一段代码,该代码使用jQuery的$ .getJSON从Flickr中提取一些照片。这样做的原因是$ .getJSON不提供错误处理或使用超时。 由于$ .getJSON只是$ .ajax的包装,因此我决定重写该内容并感到惊讶,它可以完美地工作。 现在,乐趣开始了。当我故意导致404(通过更改URL)或导致网络超时(由于未连接到互连网)时,错误事件根本不会触发。我对我做错了事感到茫然。非常感谢您的帮助。 这是代码: $(document).ready(function(){ // var jsonFeed = "http://api.flickr.com/services/feeds/photos_public.gne"; // correct URL var jsonFeed = "http://api.flickr.com/services/feeds/photos_public.gne_______"; // this should throw a 404 $.ajax({ url: jsonFeed, data: { "lang" : "en-us", "format" : "json", "tags" : "sunset" }, dataType: "jsonp", jsonp: "jsoncallback", timeout: 5000, success: function(data, …

6
Twitter Bootstrap CSS类的jQuery show()已隐藏
我正在使用Twitter Bootstrap,我注意到jQuery show()或fadeIn()没有使用类标记的DOM元素hidden出现,因为jQuery函数仅删除了display: none规范。但是,那visibility仍设置为hidden。 我想知道解决此问题的最佳方法是什么? 删除hidden元素上的类 更改可见性属性 在我自己的CSS中覆盖隐藏的类 特别是,我想知道用jQuery还是css进行修复是否更好以及为什么。

3
如何使用jquery动态更改iframe中的内容?
我想知道是否可能有一个包含iframe和一些jquery代码的网站,该代码每30秒更改一次iframe内容。内容在不同的网页中。 像这样: <html> <head> <script type="text/javascript" src="jquery.js"></script> <script> $(document).ready(function(){ var array = new array(); array[0] = 'http://webPage1.com'; array[1] = 'http://webPage2.com'; // And so on. // Do something here to change the iframe every 30 second }); </script> </head> <body> <iframe id="frame"></iframe> </body> </html>
89 jquery  iframe 

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.