Tag: jQuery

使用jQuery获取所选的选项ID

我试图使用jQuery根据选定的选项进行ajax请求。 有没有简单的方法来检索使用jQuery选定的选项id (例如“id2”)? <select id="my_select"> <option value="o1" id="id1">Option1</option> <option value="o2" id="id2">Option2</option> </select> $("#my_select").change(function() { //do something with the id of the selected option });

无法使用HTML设置未定义的jQuery UI自动完成属性“_renderItem”

我使用下面的代码来呈现我的jQuery UI自动完成项目为HTML。 这些项目在自动完成控件中正确呈现,但我不断收到此javascript错误,不能移动它。 Firefox 无法转换JavaScript参数 Chrome 无法设置未定义属性“_renderItem” donor.GetFriends(function (response) { // setup message to friends search autocomplete all_friends = []; if (response) { for (var i = 0; i < response.all.length – 1; i++) { all_friends.push({ "label":"<img style='padding-top: 5px; width: 46px; height: 46px;' src='/uploads/profile-pictures/" + response.all[i].image + "'/><br/><strong style='margin-left: 55px; margin-top: -40px; float:left;'>" + response.all[i].firstname […]

jQuery UI自动完成宽度设置不正确

我已经实现了一个jQuery UI自动完成框,而不是作为文本框的宽度,下拉选项正在扩展,以填充页面的剩余宽度。 看看这个例子,看看它自己: http : //jsbin.com/ojoxa4 创build后立即尝试设置列表的宽度,如下所示: $('.ui-autocomplete:last').css('width', $('#currentControlID').width() ); 这似乎什么都不做。 我也尝试使用页面样式设置宽度: ui-autocomplete { width: 500px; } 这样做的确令人吃惊,但是这意味着页面上的所有autocompletes必须是相同的宽度,这并不理想。 有没有办法单独设置每个菜单的宽度? 或者更好,任何人都可以解释为什么宽度不正确的工作?

如果一千或更多,如何将数字格式化为2.5K,否则在JavaScript中为900?

我需要显示1K等于一千,或者1.1K,1.2K,1.9K等格式的货币值,如果不是千,那么千元以下显示正常500,100,250等,使用JavaScript来格式化数字?

testing空的jQueryselect结果

说我同意 var s = $('#something'); 接下来我想testingjQuery是否find#something,即我想testings是否为空。 我可以使用我的可靠的isempty() : function isempty(o) { for ( var i in o ) return false; return true; } 或者因为jQuery对象是数组,我想我可以testings.length 。 但是jQuery的用法看起来都不怎么样,jQueryesque也不是。 你有什么build议?

WordPress的3.5自定义媒体上传为您的主题选项

WordPress的3.5最近已经发布,我通过thickbox和window.send_to_editor WordPress媒体上传系统在我的WordPress主题(背景,标志等)的一些选项。 但正如你所知,Wordpress已经集成了一个新的媒体pipe理器,我想用这个新function上传图片/文件作为自定义字段。 所以我花了早上find一个方法来获得希望的结果。 我发现与这个解决scheme,这可能对你们中的一些人有用。 感谢您向我提供关于代码的意见或任何改进意见! HTML示例: <a href="#" class="custom_media_upload">Upload</a> <img class="custom_media_image" src="" /> <input class="custom_media_url" type="text" name="attachment_url" value=""> <input class="custom_media_id" type="text" name="attachment_id" value=""> jQuery代码: $('.custom_media_upload').click(function() { var send_attachment_bkp = wp.media.editor.send.attachment; wp.media.editor.send.attachment = function(props, attachment) { $('.custom_media_image').attr('src', attachment.url); $('.custom_media_url').val(attachment.url); $('.custom_media_id').val(attachment.id); wp.media.editor.send.attachment = send_attachment_bkp; } wp.media.editor.open(); return false; }); 如果您想查看attachmentvariables中包含的每个设置,您可以执行console.log(attachment)或alert(attachment) 。

Google图表重绘/缩放窗口大小

如何重新绘制/重新调整窗口大小的谷歌折线图?

JQuery document.ready与Phonegap deviceready

我正在用jQuery制作一个phonegap应用程序。 我很困惑,是否应该将我的整个代码包装在JQuery的$(document).ready() $(document).ready(function(){ //mycode }); 或者在phonegap的deviceready事件里面 document.addEventListener("deviceready", function(){ //mycode }); 我目前正在使用document.ready但我想我可能会遇到问题,如果我尝试访问document.ready一些Phonegap API方法。 哪个是最好的事件来包装我的代码,document.ready或deviceready?

什么JQueryselect器排除项与父母匹配给定的select器?

我有 var $set = $('.foo,.bar').filter( function() {return $(this).parents('.baz').length < 1;}); 作为一种select所有类的元素是foo或者bar而不是从类baz的元素下降的元素的方法。 是否有一个select器可以完成同样的事情,而不需要过滤lambda? <div class='foo'/><!–match this–> <div class='bar'/><!–match this–> <div class='baz'> <div class='foo'/> <!–don't match this–> </div>

我可以将表单input绑定到Backbone.js中的模型,而无需手动跟踪模糊事件?

我有一个backbone.js应用程序( www.github.com/juggy/job-board ),我想直接将我的表单input绑定到我的模型(一个Sproutcore)。 Backbone.js(或其他工具)可能不实际跟踪input上的每个模糊事件并手动更新模型吗? 这看起来像很多胶水代码。 谢谢, 朱利安