Questions tagged «jquery»

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

11
如何使用JavaScript从* .CSV文件读取数据?
我的csv数据如下所示: 标题1,标题2,标题3,标题4,标题5,值1_1,值2_1,值3_1,值4_1,值5_1,值1_2,值2_2,值3_2,值4_2,值5_2...。 您如何使用Javascript读取此数据并转换为这样的数组?: [heading1:value1_1,heading2:value2_1,heading3:value3_1,heading4:value4_1,heading5:value5_1],[heading1:value1_2,heading2:value2_2,heading3:value3_2,heading4:value4_2,heading5:value5_2] .... 我已经尝试过此代码,但是没有运气!: <script type="text/javascript"> var allText =[]; var allTextLines = []; var Lines = []; var txtFile = new XMLHttpRequest(); txtFile.open("GET", "file://d:/data.txt", true); txtFile.onreadystatechange = function() { allText = txtFile.responseText; allTextLines = allText.split(/\r\n|\n/); }; document.write(allTextLines);<br> document.write(allText);<br> document.write(txtFile);<br> </script>
192 javascript  jquery 


20
如何使用方法创建jQuery插件?
我正在尝试编写一个jQuery插件,它将为调用它的对象提供其他功能/方法。我在线阅读的所有教程(过去2个小时内一直在浏览)最多都包含如何添加选项,但不包含其他功能。 这是我想要做的: //通过调用该div的插件将div格式化为消息容器 $("#mydiv").messagePlugin(); $("#mydiv").messagePlugin().saySomething("hello"); 或类似的规定。归结为以下几点:调用插件,然后调用与该插件关联的函数。我似乎找不到找到这种方法的方法,而且我以前看过很多插件都这样做。 这是到目前为止我对插件的了解: jQuery.fn.messagePlugin = function() { return this.each(function(){ alert(this); }); //i tried to do this, but it does not seem to work jQuery.fn.messagePlugin.saySomething = function(message){ $(this).html(message); } }; 我该如何实现这样的目标? 谢谢! 更新2013年11月18日:我已更改对Hari以下评论和支持的正确答案。

4
如何处理Twitter Bootstrap中的模式关闭事件?
在Twitter引导程序中,查看模态文档。我无法弄清楚是否有办法监听模态的close事件并执行函数。 例如,以该模式为例: <div class="modal-header"> <button type="button" class="close close_link" data-dismiss="modal" aria-hidden="true">×</button> <h3>Modal header</h3> </div> <div class="modal-body"> ... </div> <div class="modal-footer"> <a href="#" class="btn close_link" data-dismiss="modal">Close</a> </div> 由于,顶部的X按钮和底部的关闭按钮都可以隐藏/关闭模式data-dismiss="modal"。所以我想知道,是否可以听一下? 另外,我想我可以像这样手动进行... $("#salesitems_modal").load(url, data, function() { $(this).modal('show'); $(this).find(".close_link").click(modal_closing); }); 你怎么看?



8
Google Closure Library通过jQuery提供了什么?[关闭]
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案会得到事实,参考或专业知识的支持,但是这个问题可能会引起辩论,争论,民意测验或进一步的讨论。如果您认为此问题可以解决并且可以重新提出,请访问帮助中心以获取指导。 7年前关闭。 考虑中 商业背景 社区支持 可用的扩展 默认功能集 使用简单 和可靠性 为什么您偏爱另一个?

10
如何使用jQuery / JavaScript解析JSON数据?
我有一个AJAX调用,返回的是这样的JSON: $(document).ready(function () { $.ajax({ type: 'GET', url: 'http://example/functions.php', data: { get_param: 'value' }, success: function (data) { var names = data $('#cand').html(data); } }); }); 在#canddiv中,我将得到: [ { "id" : "1", "name" : "test1" }, { "id" : "2", "name" : "test2" }, { "id" : "3", "name" : …
190 jquery  ajax  json  parsing 

7
jQuery等同于JavaScript的addEventListener方法
我试图找到与此JavaScript方法调用等效的jQuery: document.addEventListener('click', select_element, true); 我已经达到: $(document).click(select_element); 但这无法达到与JavaScript方法的最后一个参数相同的结果-一个布尔值,指示是否应在捕获或冒泡阶段执行事件处理程序(根据我对http://www.quirksmode.org的了解)/js/events_advanced.html)-被忽略。 如何使用jQuery指定该参数或以其他方式实现相同的功能?

9
jQuery在窗口上调整大小
我有以下JQuery代码: $(document).ready(function () { var $containerHeight = $(window).height(); if ($containerHeight <= 818) { $('.footer').css({ position: 'static', bottom: 'auto', left: 'auto' }); } if ($containerHeight > 819) { $('.footer').css({ position: 'absolute', bottom: '3px', left: '0px' }); } }); 唯一的问题是,这仅在首次加载浏览器时有效,我是否containerHeight还希望在调整窗口大小时进行检查? 有任何想法吗?
190 jquery  html  css 


23
未捕获的SyntaxError:带有JSON.parse的意外令牌
是什么导致第三行出现此错误? var products = [{ "name": "Pizza", "price": "10", "quantity": "7" }, { "name": "Cerveja", "price": "12", "quantity": "5" }, { "name": "Hamburguer", "price": "10", "quantity": "2" }, { "name": "Fraldas", "price": "6", "quantity": "2" }]; console.log(products); var b = JSON.parse(products); //unexpected token o 运行代码段隐藏结果展开摘要 打开控制台以查看错误
190 javascript  jquery  json 

10
如何在contenteditable元素(div)中设置插入符(光标)的位置?
我以这个简单的HTML为例: <div id="editable" contenteditable="true"> text text text<br> text text text<br> text text text<br> </div> <button id="button">focus</button> 我想要简单的事情-单击按钮时,我想将插入符号(光标)放入可编辑div中的特定位置。通过网络搜索,我将这个JS附加到了按钮点击上,但是它不起作用(FF,Chrome): var range = document.createRange(); var myDiv = document.getElementById("editable"); range.setStart(myDiv, 5); range.setEnd(myDiv, 5); 是否可以像这样手动设置插入符号的位置?

6
使用jQuery切换输入禁用属性
这是我的代码: $("#product1 :checkbox").click(function(){ $(this) .closest('tr') // Find the parent row. .find(":input[type='text']") // Find text elements in that row. .attr('disabled',false).toggleClass('disabled') // Enable them. .end() // Go back to the row. .siblings() // Get its siblings .find(":input[type='text']") // Find text elements in those rows. .attr('disabled',true).removeClass('disabled'); // Disable them. }); 如何切换.attr('disabled',false);? 我似乎在Google上找不到它。
189 jquery  toggle  attr 

21
在运行时使用jQuery创建CSS规则/类
通常我有一个CSS文件,该文件具有以下规则: #my-window { position: fixed; z-index: 102; display:none; top:50%; left:50%; } 如何通过在运行时操作期间将CSS信息添加到正文或类似内容来避免创建这样的静态CSS文件?(仅使用jQuery) 我只想用jQuery定义一次,以后再使用多次;这就是为什么我不想每次都将其添加到特定的DOM元素。 我知道简单的功能(css("attr1", "value");),但是如何创建完整的可重用CSS规则?
189 jquery  css 

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.