jQuery插件开发:return this.each()是什么意思?

我找到书面的解释是,通过返回当前对象,来维护链式调用。

但是我的问题是,直接return this不可以吗?
直接return this返回的不也是jQuery选择器获取的jQuery对象吗?
为什么后面要加上each()呢?

5个回答

因为each返回的也是this对象,所以直接return this.each可以执行你的相关操作,还可以保持链式调用功能

你看这个each调用的是什么方法,,应该是遍历

因为this.each保证了遍历完成才执行下一个操作,否则迭代是延迟执行的,前面的插件并没有实际执行。

我感觉 return this.each(),就相当于 this.each();return this; 那么写只是简写为了方便

使用each的作用在于执行each可以带function参数,循环执行你要执行的操作。
如果单从链式角度和返回值出发,返回this和this.each返回的是一致的。

 return this.each(function() {
            $(this).append(' - ' + $(this).data('x'));
        });
                等价于
             var objs = this;
        for (var i=0; i<objs.length; i++) {
            var obj = objs[i];
            $(obj).append(' - ' + $(obj).data('x'));
        };
        return this;
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
获得Jquery插件内的函数返回值

我是菜鸟。改造了一个Jquery插件,大致结构如下: (function ($) { "use strict"; //构造函数 var Combobox = function (element, options) { this.$element = element; ... }; //方法 Combobox.prototype = { constructor: Combobox , load: function (keyword) { ... } ... , getvalue: function () { return this.$element.val(); } }; $.fn.combobox = function (option) { return this.each(function () { var $this = $(this) , data = $this.data('combobox') , options = typeof option == 'object' && option; if (!data) { $this.data('combobox', (data = new Combobox(this, options))); } if (typeof option == 'string') { data[option](); } }); }; //默认值 $.fn.combobox.defaults = { menu: '<ul class="typeahead-long dropdown-menu"></ul>' , item: '<li><a href="#" class="dropdown-item"></a></li>' , datasource: '' }; })(jQuery); 在Html中是这样调用的: <script> $(document).ready(function () { $('.combobox').combobox(); }); </script> 它工作的很好。除了这个需求: 我想在html通过JavaScript中获得getvalue函数的返回值: var value = $("#sn").combobox('getvalue'); alert(value); alert总是显示[object Object]。 请教高手:我哪里做错了? 能否给个详细的解答,叩首!!!

jquery这五行代码分别是什么意思呢?

[align=center][size=x-large]哥刚学jquery.学习插件时遇到一些问题,很疑惑,大神们,现身吧~[/size][/align] [code="java"]$.fn.gparents= function () { var gparents=[]; $.each(this,function(i,n){ gparents.push(n.parentNode); }); gparents=$.unique(gparents);// alert([color=red]this[/color].attr('name'));//this是jquery对象. 莫非是function本身? return this.[color=red]pushStack[/color](gparents);//setArray方法无效什么原因呢? pushStack又是什么方法, }[/code] 以上代码中: 1,this到底是什么意思? 2,pushStack和setArray是哪里的函数啊?查了jquery手册木有啊,在DOM手册也木有啊..

简单的jQuery分页插件封装怎么进行?

在学习jQuery插件封装,依葫芦画瓢封装了一个简单的表格和分页,页面能初始化生成表格和分页,但生成后怎么能让分页插件执行分页和表格刷新工作就不晓得怎么继续了,希望熟悉jQuery插件开发的人能帮忙补齐一下。 预期的用法是,给插件传入一个后台的请求路径“"http://127.0.0.1:8080/account/findListForPage"”,通过路径返回一个分页json对象(当前页、总页、页面表格数据),通过解析json生成表格和分页部分: [code="js"] function reloadTable(code){ $("#acTableGrid").grid({ //content:$(".widget-body"), type: "POST", url:"${ctx}/account/findListForPage", column:[{"id":"编号","state":"状态","type":"类型","phone":"电话"}], page:true, param:{"pageCode":code}, }) } [/code] [code="js"] (function($) { // plugin definition var GridTable = function(ele, options) { this.$element = ele, this.defaults = { page : false, type : "GET", url : undefined, param : undefined, pageData : undefined }, this.opts = $.extend({}, this.defaults, options) if(this.opts.url!=undefined&&this.opts.url!=""){ var dataObject = $.ajax({ async: false, type : this.opts.type, url : this.opts.url, data : this.opts.param, success : function(data) { return data } }); } this.opts.pageData = dataObject.responseJSON; } GridTable.prototype = { buildBody : function() { this.$element.empty(); this.$element.addClass("table table-striped table-bordered table-hover"); if (this.opts.column.length > 0) { var thead = $("<thead>"); var tr = $("<tr>").appendTo(thead); $.each(this.opts.column[0], function(name, value) { tr.append("<th>" + value + "</th>"); }); this.$element.append(thead) } var record = this.opts.pageData.data; if (record != undefined && record.length > 0) { var tbody = $("<tbody>"); for (i = 0; i < record.length; i++) { columnData = record[i]; var tr = $("<tr>"); $.each(this.opts.column[0], function(name, value) { tr.append("<td>" + columnData[name] + "</td>"); }); tbody.append(tr); } return this.$element.append(tbody) } }, buildPagin: function(){ var pageData = this.opts.pageData; if (this.opts.page) { var page = '<div class="dt-row dt-bottom-row">'; page = page + ' <input type="hidden" id="url" name="url" value="' + this.opts.url + '">'; page = page + ' <input type="hidden" id="pageSize" name="pageSize" value="' + pageData.pageSize + '">'; page = page + ' <input type="hidden" id="pageCode" name="pageCode" value="' + pageData.pageCode + '">'; page = page + ' <input type="hidden" id="totalPageNum" name="totalPageNum" value="' + pageData.totalPageNum + '">'; page = page + ' <div class="row">'; page = page + ' <div class="col-sm-6">'; page = page + ' <div class="dataTables_info" id="dt_basic_info">第' + pageData.pageCode + '/' + pageData.totalPageNum + '页 共' + pageData.totalRecords + '条记录</div>'; page = page + ' </div>'; page = page + ' <div class="col-sm-6 text-right">'; page = page + ' <div class="dataTables_paginate paging_bootstrap_full">'; page = page + ' <ul class="pagination">'; page = page + ' <li class="first"><a href="javascript:void(0)">首页</a></li>'; page = page + ' <li class="prev"><a href="javascript:void(0)">上一页</a></li>'; page = page + ' <li class="next"><a href="javascript:void(0)">下一页</a></li>'; page = page + ' <li class="last"><a href="javascript:void(0)">末尾页</a></li>'; page = page + ' </ul>'; page = page + ' </div>'; page = page + ' </div>'; page = page + ' </div>'; page = page + ' </div>'; this.$element.after(page); }, } $.fn.grid = function(options) { var grid = new GridTable(this, options); grid.buildBody(); grid.buildPagin(); return grid; }; })(jQuery); [/code] 生成的HTML结构如下: [code="html"] //表格数据部分 <table id="acTableGrid" class="table table-striped table-bordered table-hover"><thead><tr><th>编号</th><th>状态</th><th>类型</th><th>电话</th><th>账号</th><th>注册时间</th><th>Email</th></tr></thead><tbody><tr><td>464690392101687300</td><td>null</td><td>0</td><td>null</td><td>15828245173</td><td>1399625797000</td><td>null</td></tr><tr><td>465404813799198700</td><td>null</td><td>0</td><td>null</td><td>313057544@qq.com</td><td>1399796129000</td><td>null</td></tr><tr><td>465442761785610240</td><td>null</td><td>0</td><td>null</td><td>15828245273</td><td>1399805176000</td><td>null</td></tr></tbody></table> //分页部分 <div class="dt-row dt-bottom-row"> <input type="hidden" id="url" name="url" value="/kmp/account/findListForPage"> <input type="hidden" id="pageSize" name="pageSize" value="3"> <input type="hidden" id="pageCode" name="pageCode" value="1"> <input type="hidden" id="totalPageNum" name="totalPageNum" value="3"> <div class="row"> <div class="col-sm-6"> <div class="dataTables_info" id="dt_basic_info">第1/3页 共7条记录</div> </div> <div class="col-sm-6 text-right"> <div class="dataTables_paginate paging_bootstrap_full"> <ul class="pagination"> <li class="first"><a href="javascript:void(0)">首页</a></li> <li class="prev"><a href="javascript:void(0)">上一页</a></li> <li class="next"><a href="javascript:void(0)">下一页</a></li> <li class="last"><a href="javascript:void(0)">末尾页</a></li> </ul> </div> </div> </div> </div> [/code]

如何为ajax添加/修改jQuery工具提示插件 - 如何添加实时功能?

<div class="post-text" itemprop="text"> <p>I use this plugin for jQuery: <a href="http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/" rel="nofollow">http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/</a></p> <p>I would like add or modify this for add function live(), because now doesn't working with use Ajax.</p> <p><strong>all code:</strong> <a href="http://pastebin.com/up6KYKCN" rel="nofollow">http://pastebin.com/up6KYKCN</a></p> <p>start in 47 line:</p> <pre><code>$.fn.extend({ tooltip: function(settings) { settings = $.extend({}, $.tooltip.defaults, settings); createHelper(settings); return this.each(function() { $.data(this, "tooltip", settings); this.tOpacity = helper.parent.css("opacity"); // copy tooltip into its own expando and remove the title this.tooltipText = this.title; $(this).removeAttr("title"); // also remove alt attribute to prevent default tooltip in IE this.alt = ""; }) .mouseover(save) .mouseout(hide) .click(hide); }, </code></pre> <p>probably here must change mouseover(save) and add live(), but how?</p> </div>

save the transient instance before flushing:

SSH开发save()报错: 严重: Exception occurred during processing request: object references an unsaved transient instance - save the transient instance before flushing: com.resume.demain.Resume org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.resume.demain.Resume at org.hibernate.engine.internal.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:279) at org.hibernate.type.EntityType.getIdentifier(EntityType.java:455) at org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:281) at org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:291) at org.hibernate.type.TypeHelper.findDirty(TypeHelper.java:296) at org.hibernate.persister.entity.AbstractEntityPersister.findDirty(AbstractEntityPersister.java:4079) at org.hibernate.event.internal.DefaultFlushEntityEventListener.dirtyCheck(DefaultFlushEntityEventListener.java:532) at org.hibernate.event.internal.DefaultFlushEntityEventListener.isUpdateNecessary(DefaultFlushEntityEventListener.java:215) at org.hibernate.event.internal.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:142) at org.hibernate.event.internal.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:216) at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:85) at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:38) at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1224) at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:464) at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:2905) at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2281) at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:485) at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:146) at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$100(JdbcResourceLocalTransactionCoordinatorImpl.java:38) at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:230) at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:65) at com.resume.dao.impl.ResumeDaoImpl.save(ResumeDaoImpl.java:28) at com.resume.service.impl.ResumeServiceImpl.save(ResumeServiceImpl.java:25) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) 前台jsp页面,动态添加: <script type="text/javascript" src="js/jquery-1.8.0.js"></script> <script type="text/javascript"> $(function() { $("#btnAddeducation").click( function() { var num = $("#educationhidNum").val(); num = parseInt(num); num++; $("#educationhidNum").val(num); $("#edcationaddtable").clone(true).attr("id", "edcationaddtable" + num).appendTo("#educationbackgrroundadd"); //clone $("#edcationaddtable" + num).each(function() { $(this).find("input[type='text']").val(""); $(this).find("input[name='educationBackgroundlist[0].startTime']").attr("id","educationStartTime"+ num).attr("name","educationBackgroundlist["+ num+"].startTime"); $(this).find("input[name='educationBackgroundlist[0].university']").attr("id","university"+ num).attr("name","educationBackgroundlist["+ num+"].university"); $(this).find("input[name='educationBackgroundlist[0].overTime']").attr("id","educationOverTime"+ num).attr("name","educationBackgroundlist["+ num+"].overTime"); $(this).find("input[name='educationBackgroundlist[0].professional']").attr("id","professional"+ num).attr("name","educationBackgroundlist["+ num+"].professional"); $(this).find("input[name='educationBackgroundlist[0].qualification']").attr("id","qualification"+ num).attr("name","educationBackgroundlist["+ num+"].qualification"); $(this).find("input[name='deletenum']").attr("class","edcationdeletetable"+ num).attr("name","deletenum"+ num).attr("onclick","deletethiseducation('"+num+"')"); }); }); }); </script> <script type="text/javascript"> function deletethiseducation(a){ a = parseInt(a); if(a==0){ alert("该项不能删除!"); return; } document.getElementById("edcationaddtable"+a).remove(); } </script> <div id="educationbackgrroundadd"> <table id = "edcationaddtable"> <tr> <td colspan="4" style="font-weight:bold; font-size:20px;">教育背景:</td> </tr> <tr> <td>开始&nbsp;时间:<input type="text" name="educationBackgroundlist[0].startTime" id="educationStartTime" /></td> <td ></td> <td >学&nbsp;&nbsp;&nbsp;校:<input type="text" name="educationBackgroundlist[0].university" id="university" /></td> <td ></td> </tr> <tr> <td>结束&nbsp;时间:<input type="text" name="educationBackgroundlist[0].overTime" id="educationOverTime" /></td> <td></td> <td>专&nbsp;&nbsp;&nbsp;业:<input type="text" name="educationBackgroundlist[0].professional" id="professional" /></td> <td></td> </tr> <tr> <td>学&nbsp;&nbsp;&nbsp;位:<input type="text" name="educationBackgroundlist[0].qualification" id="qualification" /></td> <td></td> <td> </td> <td><input type="button" name="deletenum" class="edcationdeletetable" value="点击删除" onclick="deletethiseducation('0')" /></td> </tr> </table> <table> <tr> <td></td> <td></td> <td></td> <td> <input id="educationhidNum" type="hidden" name="hidNum" value="0" /> <input type="button" style="margin-left:100%;" value="继续添加" id="btnAddeducation" onmouseover="this.style.backgroundColor='red';" onmouseout="this.style.backgroundColor='#d4e3e5';" /> </td> </tr> </table> 后台Action: private List<EducationBackground> educationBackgroundlist = new ArrayList<EducationBackground>(); public Resume backresume() throws Exception { List<EducationBackground> educationBackgroundlist1 = this.educationBackgroundlist(); Resume resume = new Resume(); resume.setResumeID(resumeID); resume.setApartment(apartment); resume.setAppliedPosition(appliedPosition); resume.setDestination(destination); resume.setEducationBackground(educationBackgroundlist1); resume.setEmail(email); resume.setEvaluation(evaluation); resume.setExpectation(expectation); resume.setFamilySituation(familySituation); resume.setLanguageProficiency(languageProficiency); resume.setMotivation(motivation); resume.setNationality(nationality); resume.setOperatingTime(operatingTime); resume.setOperator(operator); resume.setOther(other); resume.setPersonalAge(personalAge); resume.setPersonalName(personalName); resume.setPersonalSex(personalSex); resume.setPhoneNum(phoneNum); resume.setResumeState(resumeState); resume.setSourceCompany(sourceCompany); resume.setWorkSeniority(workSeniority); return resume; } public String addresume() throws Exception { Resume resume = this.backresume(); resumeService.save(resume); Pageres pageres = this.pageser(); list = resumeService.queryresumelist(resume,pageres,workSeniority1,workSeniority2,pageNo,pageSize); return SUCCESS; } Resume简历为主表,EducationBackground为简历从表教育背景表,两个表都有主外键关系, @OneToMany(fetch = FetchType.EAGER,targetEntity=EducationBackground.class,cascade={CascadeType.ALL},orphanRemoval=true) // @Cascade(value={org.hibernate.annotations.CascadeType.ALL}) // @NotFound(action = NotFoundAction.IGNORE) @JoinColumn(name="resume_id") public List<EducationBackground> getEducationBackground() { return educationBackground; } public void setEducationBackground(List<EducationBackground> educationBackground) { this.educationBackground = educationBackground; } @ManyToOne(targetEntity=Resume.class,fetch = FetchType.EAGER) @JoinColumn(name="resume_id",referencedColumnName="resumeID", insertable=true, updatable=true) public Resume getResume() { return resume; } public void setResume(Resume resume) { this.resume = resume; } 数据访问层的sava()方法; @Override public void save(Resume resume) { Session session = sessionFactory.openSession(); //Session session = sessionFactory.getCurrentSession(); Transaction tx = session.beginTransaction(); //session.persist(resume); //session.save(resume); session.persist(resume); tx.commit(); session.close(); } 当我在action中手动添加教育背景的数据时,数据为多条,可以插入数据库,但是我换成jsp动态添加时 就报上面的错误,是怎么回事啊 ?? 求大神帮帮忙,万分感谢!

修复jQuery插件以处理具有唯一ID的重复嵌套字段

<div class="post-text" itemprop="text"> <p>I have a quick question for you guys here. I was handed a set of lead generation pages and asked to get them up and running. The forms are great, expect for one small issue... they use the jQuery below to allow users to submit multiple instances of a data set by clicking an "Add another item" button. The problem is that the duplicated items are duplicated EXACTLY. Same name, id, etc. Obviously, this doesn't work when attempting to process the data via PHP, as only the first set is used.</p> <p>I'm still learning jQuery, so I was hoping that someone could point me in the right direction for how to modify the plugin below to assign each duplicated field an incremental integer on the end of the ID and name assigned. So, the fields in each dataset are Role, Description, Age. Each additional dataset will use the ID &amp; name syntax of fieldname#, where # represents numbers increasing by 1.</p> <p>Thanks in advance for any advice! </p> <p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>/** https://github.com/ReallyGood/jQuery.duplicate */ $.duplicate = function(){ var body = $('body'); body.off('duplicate'); var templates = {}; var settings = {}; var init = function(){ $('[data-duplicate]').each(function(){ var name = $(this).data('duplicate'); var template = $('&lt;div&gt;').html( $(this).clone(true) ).html(); var options = {}; var min = +$(this).data('duplicate-min'); options.minimum = isNaN(min) ? 1 : min; options.maximum = +$(this).data('duplicate-max') || Infinity; options.parent = $(this).parent(); settings[name] = options; templates[name] = template; }); body.on('click.duplicate', '[data-duplicate-add]', add); body.on('click.duplicate', '[data-duplicate-remove]', remove); }; function add(){ var targetName = $(this).data('duplicate-add'); var selector = $('[data-duplicate=' + targetName + ']'); var target = $(selector).last(); if(!target.length) target = $(settings[targetName].parent); var newElement = $(templates[targetName]).clone(true); if($(selector).length &gt;= settings[targetName].maximum) { $(this).trigger('duplicate.error'); return; } target.after(newElement); $(this).trigger('duplicate.add'); } function remove(){ var targetName = $(this).data('duplicate-remove'); var selector = '[data-duplicate=' + targetName + ']'; var target = $(this).closest(selector); if(!target.length) target = $(this).siblings(selector).eq(0); if(!target.length) target = $(selector).last(); if($(selector).length &lt;= settings[targetName].minimum) { $(this).trigger('duplicate.error'); return; } target.remove(); $(this).trigger('duplicate.remove'); } $(init); }; $.duplicate();</code></pre> </div> </div> </div>

如何使用Jquery-option-tree插件预加载<options>和<select>

<div class="post-text" itemprop="text"> <p>I am using Jquery-option-tree plugin on a standalone website not based on Wordpress as in example 7 on the demo page, except that I am not passing a .txt file but a PHP page is generating the array of &lt; options &gt; to be passed to the plugin.</p> <p><a href="http://kotowicz.net/jquery-option-tree/demo/demo.html" rel="nofollow noreferrer">http://kotowicz.net/jquery-option-tree/demo/demo.html</a></p> <p>This perfectly works: so let's say that the user wants to select a category for a new product, the plugin suits the purpose generating a nice: " Food -&gt; fruit -&gt; apples " upon user clicks. (see demo page ex. 7)</p> <p>What instead if a product already exists with its categories assigned? I want to show it to the user when he edit that product, preloading the tree.</p> <p>I have the ids path coming from database, so it would just be a matter of having the plugin to run without the user interact, using the value I pass. I saw this question: <a href="https://stackoverflow.com/questions/15549975/jquery-simulate-click-event-on-select-option">jQuery simulate click event on select option</a> and tried to simulate user' click with this (and other) methods with no luck.</p> <pre><code> $('#select') .val(value) .trigger('click'); </code></pre> <p>Here the call to the function:</p> <pre><code>$(function() { var options = { empty_value: '', set_value_on: 'each', indexed: true, // the data in tree is indexed by values (ids), not by labels on_each_change: '/js/jquery-option-tree/get-subtree.php', // this file will be called with 'id' parameter, JSON data must be returned choose: function(level) { return 'Choose level ' + level; }, loading_image: '/js/jquery-option-tree/ajax-load.gif', show_multiple: 10, // if true - will set the size to show all options choose: '' }; $.getJSON('/js/jquery-option-tree/get-subtree.php', function(tree) { // initialize the tree by loading the file first $('input[name=parent_category_id]').optionTree(tree, options); }); }); </code></pre> <p>Here you can see the plugin:</p> <p><a href="https://code.google.com/p/jquery-option-tree/" rel="nofollow noreferrer">https://code.google.com/p/jquery-option-tree/</a></p> </div>

JQuery想写一个不需要数据库的选座系统

网上有一些资源 但是因为是JQuery菜鸟 所以有些东西不是很清楚 现在想做一个单机版的在线选座 有点类似电影选座 选定一个座位 点击按钮选中后 刷新页面 回到更改之后的页面 然后 先前被选中的座位就不能再次被选中 <body> <div id="header"> <div id="logo"><h1><a href="http://www.helloweba.com" title="返回helloweba首页">helloweba</a></h1></div> </div> <div id="main"> <h2 class="top_title">选座</a></h2> <div class="demo"> <div id="seat-map"> <div class="front">屏幕</div> </div> <div class="booking-details"> <p>座位:</p> <ul id="selected-seats"></ul> <p>姓名:<span id="counter">0</span></p> <p>学费:<b>¥<span id="total">0</span></b></p> <button class="checkout-button" >选定</button> <div id="legend"></div> </div> <div style="clear:both"></div> </div> <br/> </div> <script type="text/javascript" src="http://libs.useso.com/js/jquery/1.7.2/jquery.min.js"></script> <script type="text/javascript" src="jquery.seat-charts.min.js"></script> <script type="text/javascript"> var price = 80; //票价 $(document).ready(function(){ $("button").click(function(){ $counter.text(sc.find('selected').length+1); return 'selected'; }); }); $(document).ready(function() { var $cart = $('#selected-seats'), //座位区 $counter = $('#counter'), //票数 $total = $('#total'); //总计金额 var sc = $('#seat-map').seatCharts({ map: [ //座位图 'aaaaa_aaaaa', 'aaaaa_aaaaa', '__________', 'aaaaa_aaaa', 'aaaaa_aaaa', 'aaaaa_aaaa', 'aaaaa_aaaa', 'aaaaa_aaaa', 'aaaaa_aaaa', 'aaaaa_aaaa' ], naming : { top : false, getLabel : function (character, row, column) { return column; } }, legend : { //定义图例 node : $('#legend'), items : [ [ 'a', 'available', '可选座' ], [ 'a', 'unavailable', '已被选'] ] }, click: function () { //点击事件 if (this.status() == 'available') { //可选座 $('<li>'+(this.settings.row+1)+'排'+this.settings.label+'座</li>') .attr('id', 'cart-item-'+this.settings.id) .data('seatId', this.settings.id) .appendTo($cart); $counter.text(sc.find('selected').length+1); $total.text(recalculateTotal(sc)+price); return 'selected'; } else if (this.status() == 'selected') { //已选中 //更新数量 $counter.text(sc.find('selected').length-1); //更新总计 $total.text(recalculateTotal(sc)-price); //删除已预订座位 $('#cart-item-'+this.settings.id).remove(); //可选座 return 'available'; } else if (this.status() == 'unavailable') { //已售出 return 'unavailable'; } else { return this.style(); } } }); //已售出的座位 sc.get(['1_2', '4_4','4_5','6_6','6_7','8_5','8_6','8_7','8_8', '10_1', '10_2']).status('unavailable'); }); //计算总金额 function recalculateTotal(sc) { var total = 0; sc.find('selected').each(function () { total += price; }); return total; } </script> 这是网上下载的代码 我自己改了一部分 直接蒙圈 求大神!

jQuery Cookie插件保存选择值?

<div class="post-text" itemprop="text"> <p>I have a series of two chained selects using ajax that work great. I need to be able to store/save the first select in a cookie for future visits but can't quite figure out how/what to do within the existing code?</p> <pre><code>$(function(){ var questions = $('#questions'); function refreshSelects(){ var selects = questions.find('select'); // Lets not do chosen on the first select selects.not(":first").chosen({ disable_search_threshold: true }); // Listen for changes selects.unbind('change').bind('change',function(){ // The selected option var selected = $(this).find('option').eq(this.selectedIndex); // Look up the data-connection attribute var connection = selected.data('connection'); // Removing the li containers that follow (if any) selected.closest('#questions li').nextAll().remove(); if(connection){ fetchSelect(connection); } }); } var working = false; function fetchSelect(val){ if(working){ return false; } working = true; $.getJSON('citibank.php',{key:val},function(r){ var connection, options = ''; switch (r.type) { case 'select': $.each(r.items,function(k,v){ connection = ''; if(v){ connection = 'data-connection="'+v+'"'; } options+= '&lt;option value="'+k+'" '+connection+'&gt;'+k+'&lt;/option&gt;'; }); if(r.defaultText){ // The chose plugin requires that we add an empty option // element if we want to display a "Please choose" text options = '&lt;option&gt;&lt;/option&gt;'+options; } // Building the markup for the select section $('&lt;li&gt;\ &lt;p&gt;'+r.title+'&lt;/p&gt;\ &lt;select data-placeholder="'+r.defaultText+'"&gt;\ '+ options +'\ &lt;/select&gt;\ &lt;span class="divider"&gt;&lt;/span&gt;\ &lt;/li&gt;').appendTo(questions); refreshSelects(); break; case 'html': $(r.html).appendTo(questions); break; } working = false; }); } $('#preloader').ajaxStart(function(){ $(this).show(); }).ajaxStop(function(){ $(this).hide(); }); // Initially load the product select fetchSelect('callTypeSelect'); }); </code></pre> </div>

如何使用jquery表单插件发送数据数组?

<div class="post-text" itemprop="text"> <p>I'm trying to send an array of data to a php processor page that does some processing tasks such as insertion, etc... but, it seems that the data is not being sent and the php throws this error </p> <p><b>The Error:</b></p> <p><code>Notice: Undefined index: reci in C:\Users\YASIN\Desktop\SERVER\htdocs\drawer_mess_page_process.php on line 67 Warning: array_map(): Argument #2 should be an array in C:\Users\YASIN\Desktop\SERVER\htdocs\drawer_mess_page_process.php on line 67</code></p> <p><b>The jquery code that sends the data:</b></p> <pre><code> $(document).ready(function () { var reci_arr = []; var i = 0; $('.recipient_tab').each(function(){ var a = $(this).attr('data-recipient'); reci_arr[i++] = $(this).attr('data-recipient'); }); var time=new Date().getTime(); var options = { url:'processor.php', type:'POST', resetForm:true, data:{reci:reci_arr,time:time},// the data reci is not being sent other data is being sent beforeSend:function(html){ }, success:function(html) { //doing stuffs which works }, }; $('#hide_selector_mess_draw').change(function() { $('#add_photo_mess_draw').ajaxForm(options).submit(); }); }); </code></pre> <p><b>The php code that processes the data</b></p> <pre><code>function clean_arr ($a) { $db = mysqli_connect("localhost", "root", "stark1998" ,"users") or die("Could not connect database"); return mysqli_real_escape_string($db, $a); } $reci= array_map('clean_arr', $_POST['reci']);//to_acc </code></pre> </div>

回声知识库Wordpress插件的问题

<div class="post-text" itemprop="text"> <p>I use echo KB WordPress plugin to show my website Faqs. but the problem is I have 7 different categories and plugin supports only 6 categories for displaying items in tabs layout and when you add 7th category its face automatically changes to the dropdown menu, not tabs. so I want to have 7 tabs without converting to the drop-down. I reviewed all PHP and JS files in this plugin and I found this JS file that I think is related to my problem ( where //dropdown begins) :</p> <p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>// Tabs Layout: switch to the top category user clicked on tabContainer.find( navTabsLi ).each(function(){ $(this).on('click', function (){ tabContainer.find( navTabsLi ).removeClass('active'); $(this).addClass('active'); tabContainer.find(tabPanel).removeClass('active'); changePanels ( $(this).index() ); updateTabURL( $(this).attr('id'), $(this).data('cat-name') ); }); }); // Tabs Layout: MOBILE: switch to the top category user selected $( "#main-category-selection" ).change(function() { tabContainer.find(tabPanel).removeClass('active'); // drop down $( "#main-category-selection option:selected" ).each(function() { var selected_index = $( this ).index(); changePanels ( selected_index ); updateTabURL( $(this).attr('id'), $(this).data('cat-name') ); }); }); function update_query_string_parameter(uri, key, value) { var re = new RegExp("([?&amp;])" + key + "=.*?(&amp;|$)", "i"); var separator = uri.indexOf('?') !== -1 ? "&amp;" : "?"; if (uri.match(re)) { return uri.replace(re, '$1' + key + "=" + value + '$2'); } else { return uri + separator + key + "=" + value; } }</code></pre> </div> </div> <p><a href="https://i.stack.imgur.com/j07Ye.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/j07Ye.jpg" alt="6 categories and tabs layout is OK "></a> <a href="https://i.stack.imgur.com/p9z7b.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/p9z7b.jpg" alt="added 7th Category and it changes to drop-down menu"></a></p> <p>Echo Knowledge Base Plugin Download Page: <a href="https://wordpress.org/plugins/echo-knowledge-base/" rel="nofollow noreferrer">https://wordpress.org/plugins/echo-knowledge-base/</a></p> </div>

更改'select'文本 - JQuery fnGetColumnData插件

<div class="post-text" itemprop="text"> <p>I am using fnGetColumnData plugin for data table filtering, it is working all right, but it appears as "Select" titled dropdown, there are total 5 dropdowns, so how can i change the "Select" text and replace that with something custom name?</p> <p>Here is the Plugin Script:</p> <pre><code>&lt;script type="text/javascript" charset="utf-8"&gt; (function($) { /* * Function: fnGetColumnData * Purpose: Return an array of table values from a particular column. * Returns: array string: 1d data array * Inputs: object:oSettings - dataTable settings object. This is always the last argument past to the function * int:iColumn - the id of the column to extract the data from * bool:bUnique - optional - if set to false duplicated values are not filtered out * bool:bFiltered - optional - if set to false all the table data is used (not only the filtered) * bool:bIgnoreEmpty - optional - if set to false empty values are not filtered from the result array * Author: Benedikt Forchhammer &lt;b.forchhammer /AT\ mind2.de&gt; */ $.fn.dataTableExt.oApi.fnGetColumnData = function ( oSettings, iColumn, bUnique, bFiltered, bIgnoreEmpty ) { // check that we have a column id if ( typeof iColumn == "undefined" ) return new Array(); // by default we only want unique data if ( typeof bUnique == "undefined" ) bUnique = true; // by default we do want to only look at filtered data if ( typeof bFiltered == "undefined" ) bFiltered = true; // by default we do not want to include empty values if ( typeof bIgnoreEmpty == "undefined" ) bIgnoreEmpty = true; // list of rows which we're going to loop through var aiRows; // use only filtered rows if (bFiltered == true) aiRows = oSettings.aiDisplay; // use all rows else aiRows = oSettings.aiDisplayMaster; // all row numbers // set up data array var asResultData = new Array(); for (var i=0,c=aiRows.length; i&lt;c; i++) { iRow = aiRows[i]; var aData = this.fnGetData(iRow); var sValue = aData[iColumn]; // ignore empty values? if (bIgnoreEmpty == true &amp;&amp; sValue.length == 0) continue; // ignore unique values? else if (bUnique == true &amp;&amp; jQuery.inArray(sValue, asResultData) &gt; -1) continue; // else push the value onto the result data array else asResultData.push(sValue); } return asResultData; }}(jQuery)); function fnCreateSelect( aData ) { var r='&lt;select style="width:150px;"&gt;&lt;option value=""&gt;Select&lt;/option&gt;', i, iLen=aData.length; for ( i=0 ; i&lt;iLen ; i++ ) { r += '&lt;option value="'+aData[i]+'"&gt;'+aData[i]+'&lt;/option&gt;'; } return r+'&lt;/select&gt;'; } $(document).ready(function() { /* Initialise the DataTable */ var oTable = $('#example').dataTable( { "oLanguage": { "sSearch": "Search all columns:" } } ); /* Add a select menu for each TH element in the table footer */ $(".tfoot th").each( function ( i ) { this.innerHTML = fnCreateSelect( oTable.fnGetColumnData(i) ); $('select', this).change( function () { oTable.fnFilter( $(this).val(), i ); } ); } ); } ); &lt;/script&gt; </code></pre> <p>and the HTML where select generates:</p> <pre><code>&lt;thead class="tfoot"&gt; &lt;tr&gt; &lt;th style="border:0px;display:none;"&gt;&lt;/th&gt; &lt;th style="border:0px;"&gt;&lt;/th&gt; &lt;th style="border:0px;"&gt;&lt;/th&gt; &lt;th colspan="5" style="border:0px;display:none;"&gt;&lt;/th&gt; &lt;th style="border:0px;display:none;"&gt;&lt;/th&gt; &lt;th style="border:0px;"&gt;&lt;/th&gt; &lt;th style="border:0px;display:none;"&gt;&lt;/th&gt; &lt;th style="border:0px;display:none;"&gt;&lt;/th&gt; &lt;th style="border:0px;display:none;"&gt;&lt;/th&gt; &lt;th style="border:0px;"&gt;&lt;/th&gt; &lt;th style="border:0px;"&gt;&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; </code></pre> </div>

在IE8 / 9中使用blueimp文件上传插件的jQuery $ _FILES数组为空

<div class="post-text" itemprop="text"> <p>There's lots of questions on StackOverflow related to the Blueimp file upload plugin in IE8/9, but I can't find anything directly related to my problem.</p> <p>I'm using IE10 in the IE8/9 simulator mode. Every time the PHP $_FILES array is empty. I'm including <code>jquery.iframe-transport.js</code> and it loads fine. There are no JavaScript errors. The $_FILES array is just empty.</p> <p>I've tried commenting out the <code>dataType: 'json',</code> line which was recommended in another semi-related question, but that did not help.</p> <p>Not sure what to do here and can't find anything that relates to this. Any help is appreciated.</p> <p>Here's the JavaScript:</p> <pre><code>$('#photo-file').fileupload( { url: 'photos/upload', dataType: 'json', autoUpload: true, acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i, maxFileSize: 8000000 // 8 MB } ) .on( 'fileuploadadd', function (e, data) { console.log('fileuploadadd'); if (total_photos_queue &lt; available_photos) total_photos_queue++; else return false; } ) .on( 'fileuploadsubmit', function (e, data) { console.log('fileuploadsubmit'); progress_bar.width('0%'); progress_bar.fadeIn(); } ) .on( 'fileuploadprogressall', function (e, data) { console.log('fileuploadprogressall'); var progress = parseInt(data.loaded / data.total * 100, 10); progress_bar.css('width', progress + '%'); } ) .on( 'fileuploaddone', function (e, data) { console.log('fileuploaddone'); $.each( data.result.files, function (index, file) { if (file.filename) photo_uploaded(file.id, file.filename, file.subdir); else if (file.error) console.log('error: ' + file.error); } ); } ) .on( 'fileuploadstop', function (e) { console.log('fileuploadstop'); progress_bar.fadeOut(); } ) .prop('disabled', !$.support.fileInput) .parent().addClass($.support.fileInput ? undefined : 'disabled'); </code></pre> <p>The PHP is simply (for debugging):</p> <pre><code>var_dump($_FILES); die(); </code></pre> </div>

Jquery插件sortElements排序问题

![图片说明](https://img-ask.csdn.net/upload/201608/31/1472626133_933005.jpg) ![图片说明](https://img-ask.csdn.net/upload/201608/31/1472626147_260774.jpg) 求大神帮忙,table表格用插件sortElements排序,但是table有一列是用了rowspan,合并了几行,然后排序就乱了,不知道该怎么办 ,代码如下: ``` <table id="requests" style="border-collapse: collapse;font-size: 14px;line-height: 115%;text-align:right;max-width: 100%;table-layout: fixed;border-spacing:0" border="1" > <tr> <th class="th_color">域名</th> <th class="th_color">日期</th> <th class="th_color" id="all_num">询盘总数<span class="glyphicon glyphicon-resize-vertical"></th> <th class="th_color" id="todb_num">入库操作总数<span class="glyphicon glyphicon-resize-vertical"></th> <th class="th_color" id="normal_num">实际入库总数<span class="glyphicon glyphicon-resize-vertical"></th> <th class="th_color" id="1_num">过滤邮件数<span class="glyphicon glyphicon-resize-vertical"></th> <th class="th_color" id="2_num">格式错误邮件数<span class="glyphicon glyphicon-resize-vertical"></th> <th class="th_color" id="3_num">缺失地址邮件数<span class="glyphicon glyphicon-resize-vertical"></span></th> <th class="th_color" id="4_num">ip过滤数<span class="glyphicon glyphicon-resize-vertical"></span></th> <th class="th_color" id="percent">入库统计%<span class="glyphicon glyphicon-resize-vertical"></span></th> <th class="th_color"></th> </tr> <? $weeks=array('日','一','二','三','四','五','六'); ?> <?foreach($reg->web_reqs as $key => $web_reqs){?> <?$domain=str_replace(".","_",$key); ?> <tr> <td class="td1" id="domain_<?=$domain?>" rowspan="<?=count($web_reqs)?>"><?=$key?></td> <!-- </tr>--> <!-- --><?//$num=0;?> <!-- <tr>--> <?foreach($web_reqs as $date => $web_req){?> <!-- --><?//if($num!=0){?> <!-- <tr>--> <!-- --><?//}?> <?$week=$weeks[date('w', strtotime($date))];?> <td class="td1"><a href="javascript:void(0);" onclick='get_spiders("<?=$key?>","<?=$date?>",<?=$web_req['all_requests']?>)'><?=$date?></a>(<?=$week?>)</td> <td class="td1"><?=$web_req['all_requests']?></td> <td class="td1"><?=$web_req['todb_requests']?></td> <td class="td1"><?=$web_req['normal_requests']?></td> <td class="td1"><?=$web_req['all_status1_nums']?></td> <td class="td1"><?=$web_req['all_status2_nums']?></td> <td class="td1"><?=$web_req['all_status3_nums']?></td> <td class="td1"><?=$web_req['all_status4_nums']?></td> <td class="td1"><?=sprintf("%.2f",($web_req['normal_requests']/$web_req['all_requests'])*100)?>%</td> <?if(empty($reg->domain)){?> <td class="td1"> <a href="/index.php?r=adminStatistic/inquiry&starttime=<?=date("Y-m-d",strtotime('-7 days',strtotime($reg->to)));?>&endtime=<?=$reg->to?>&domain=<?=$key?>&subm=查询"><button id="go" onclick="go()" type="button">详细</button> </a> </td> <?}else{?> <td style="width: 120px;"> <a href="/index.php?r=adminStatistic/inquiry"><button id="back" onclick="back()" type="button">返回</button> </a> </td> <?}?> </tr> <?$num++;}?> <?}?> </table> ``` <script> var table = $('#requests'); $('#all_num,#todb_num,#normal_num,#1_num,#2_num,#3_num,#4_num,#percent') .each(function(){ var th = $(this), thIndex = th.index(), inverse = false; th.click(function(){ table.find('td.td1').filter(function(){ return $(this).index() === thIndex; }).sortElements(function(a, b){ return parseFloat($.text([a])) > parseFloat($.text([b])) ? inverse ? -1 : 1 : inverse ? 1 : -1; }, function(){ return this.parentNode; }); inverse = !inverse; }); }); $(function(){ $("input[name='starttime']").prop("disabled",""); $("input[name='endtime']").prop("disabled",""); } ); </script>

使用ajaxForm插件发布数组

<div class="post-text" itemprop="text"> <p>I'm using this plugin --&gt; <a href="http://jquery.malsup.com/form/" rel="nofollow noreferrer">http://jquery.malsup.com/form/</a></p> <p>But I can't post an array to a PHP script.</p> <p>I tried this in the beforeSubmit function:</p> <pre><code>var concepts = new Array(); $('#myTable tbody tr td span.file').each(function(){ concepts.push($(this).text()); }); arr.push({name: 'concepts',value:concepts}); </code></pre> <p>And this in the data parameter:</p> <pre><code>data: { concepts: function(){ var concepts = new Array(); $('#myTable tbody tr td span.file').each(function(){ concepts.push($(this).text()); }); return concepts; } } </code></pre> <p>But I always receive a comma separated string in the PHP script not an array like in any ajax call.</p> <pre><code>[concepts] =&gt; 20 Bafles J8 DB Line Array, 4 Bafles J12 DB Line Array, 10 Bafles J SUB, 12 Bafles B2 DB, 2 Bummpers J, 4 Bafles Q7 DB Front Fill, 12 Monitores M4 DB, 38 Amplificadores, Sub Snake, 6 Bafles Q1 DB Side Fill, 6 Bafles Q SUB DB, Centro de Carga,Andamio de 4 mts. de altura brandeados por los 4 lados con lona mesh a 1,200 dpis </code></pre> <p>The above is the result of:</p> <pre><code>print_r($_POST) </code></pre> <p>The array has 2 elements in this example.</p> <p>But my posted data has commas. I know that I can encode to JSON and then decode inside PHP script but, I prefer to send and receive an array. Is there any way to achieve this?</p> <p>I tried using processData as false, and nothing :(</p> <p>Thanks in advance!</p> </div>

MUI.Ajax 调用WebService报错?实在找不到问题。

mui.ajax 调用 WEB Service 报错 ## Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8848' is therefore not allowed access. The response had HTTP status code 500. ![图片说明](https://img-ask.csdn.net/upload/201902/12/1549956611_90481.png) ``` function getData() { var result = ""; mui.ajax("http://mobile.china-crown.com:8088/Service.asmx/GetCustomerPageList", { data: { "PageIndex": "1", "SiteID": "28822" }, dataType: 'json', type: 'get', timeout:10000,//超时时间设置为10秒; headers: { 'Content-Type': 'application/json' }, success: function(data) { mui('#Custlist').pullRefresh().endPullupToRefresh(true); //下面这坨都是在拼dom 你可以用jquery 或者是你所熟悉的angular,vue双向绑定 var model = JSON.parse(data); $.each(model, function(i, value) { result += '<li class="mui-table-view-cell mui-media">' + '<a href="javascript:;">' + '<div class="mui-media-body">' + value.CustName + '</div>' + '</a>' + '</li>'; }) var element = document.getElementById("CustomerUlID"); element.innerHTML = result; }, error: function(xhr, type, errorThrown) { //异常处理; console.log(type); } }); } ``` ``` [WebMethod] //[ScriptMethod(ResponseFormat = ResponseFormat.Json)] public void GetCustomerPageList(int PageIndex, int SiteID) { string JsonStr = ""; try { int PageSize = ConfigurationManager.AppSettings["PageSize"].ObjectToInt32(); //总数量 int Count = this.GetCustomerListCount(SiteID); PageInfo PageResult = new PageInfo(PageIndex, PageSize, Count); if (!PageResult.IsBottom) { string con = SystemHelper.GetAccountSetConnect(); string Sqlcon = ConfigurationManager.ConnectionStrings[con].ConnectionString; SqlParameter[] para = { new SqlParameter("@SiteID", Convert.ToInt32(SiteID)), new SqlParameter("@BeginPage", Convert.ToInt32(PageResult.BeginPage)), new SqlParameter("@EndPage", Convert.ToInt32(PageResult.EndPage)) }; DataTable dt = SQLDBHelper.ExecuteQueryDt(Sqlcon, "up_Sel_CustomerList", CommandType.StoredProcedure, 0, para); JsonStr = JsonHelper.DataTableToJson(dt); Context.Response.Charset = "GB2312"; //设置字符集类型 Context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); Context.Response.Write(JsonStr); Context.Response.End(); } } catch (Exception ex) { } //return JsonStr; } ```

网上找了一个banner插件 但实际使用时他的滚动效果有问题

但实际使用时 他的banner滚动过了一会 就会变得特别快,时间远远超出delay设置的 下面是的他js代码,求大神看看是哪里没有写对 (function($) { $.fn.slideBox = function(options) { var defaults = { direction: 'left', duration: 0.6, easing: 'swing', delay: 3, startIndex: 0, hideClickBar: true, clickBarRadius: 5, hideBottomBar: false, width: null, height: null }; var settings = $.extend(defaults, options || {}); var wrapper = $(this), ul = wrapper.children('ul.items'), lis = ul.find('li'), firstPic = lis.first().find('img'); var li_num = lis.size(), li_height = 0, li_width = 0; var order_by = 'ASC'; var init = function() { if (!wrapper.size()) return false; li_height = settings.height ? settings.height : lis.first().height(); li_width = settings.width ? settings.width : lis.first().width(); wrapper.css({ width: li_width + 'px', height: li_height + 'px' }); lis.css({ width: li_width + 'px', height: li_height + 'px' }); if (settings.direction == 'left') { ul.css('width', li_num * li_width + 'px') } else { ul.css('height', li_num * li_height + 'px') }; ul.find('li:eq(' + settings.startIndex + ')').addClass('active'); if (!settings.hideBottomBar) { var tips = $('<div class="tips"></div>').css('opacity', 0.6).appendTo(wrapper); var title = $('<div class="title"></div>').html(function() { var active = ul.find('li.active').find('a'), text = active.attr('title'), href = active.attr('href'); return $('<a>').attr('href', href).text(text) }).appendTo(tips); var nums = $('<div class="nums"></div>').hide().appendTo(tips); lis.each(function(i, n) { var a = $(n).find('a'), text = a.attr('title'), href = a.attr('href'), css = ''; i == settings.startIndex && (css = 'active'); $('<a>').attr('href', href).text(text).addClass(css).css('borderRadius', settings.clickBarRadius + 'px').mouseover(function() { $(this).addClass('active').siblings().removeClass('active'); ul.find('li:eq(' + $(this).index() + ')').addClass('active').siblings().removeClass('active'); start(); stop() }).appendTo(nums) }); if (settings.hideClickBar) { tips.hover(function() { nums.animate({ top: '0px' }, 'fast') }, function() { nums.animate({ top: tips.height() + 'px' }, 'fast') }); nums.show().delay(2000).animate({ top: tips.height() + 'px' }, 'fast') } else { nums.show() } }; lis.size() > 1 && start() }; var start = function() { var active = ul.find('li.active'), active_a = active.find('a'); var index = active.index(); if (settings.direction == 'left') { offset = index * li_width * -1; param = { 'left': offset + 'px' } } else { offset = index * li_height * -1; param = { 'top': offset + 'px' } }; wrapper.find('.nums').find('a:eq(' + index + ')').addClass('active').siblings().removeClass('active'); wrapper.find('.title').find('a').attr('href', active_a.attr('href')).text(active_a.attr('title')); ul.stop().animate(param, settings.duration * 1000, settings.easing, function() { active.removeClass('active'); if (order_by == 'ASC') { if (active.next().size()) { active.next().addClass('active') } else { order_by = 'DESC'; active.prev().addClass('active') } } else if (order_by == 'DESC') { if (active.prev().size()) { active.prev().addClass('active') } else { order_by = 'ASC'; active.next().addClass('active') } } }); wrapper.data('timeid', window.setTimeout(start, settings.delay * 1000)) }; var stop = function() { window.clearTimeout(wrapper.data('timeid')) }; wrapper.hover(function() { stop() }, function() { window.setTimeout(start, settings.delay * 1000); }); var imgLoader = new Image(); imgLoader.onload = function() { imgLoader.onload = null; init() }; imgLoader.src = firstPic.attr('src') } })(jQuery);

下了一个搜索代码,可按钮没反应,怎么弄啊,大虾们

``` <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>jquery下拉选择城市插件hhDrop - 站长素材</title> <link href="css/main.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="/jquery/jquery.min.js"></script> <script type="text/javascript" src="js/hhDrop.js"></script> <script> $(function(){ $('#hhDrop00').hhDrop({}); $('#hhDrop01').hhDrop({}); }) </script> </head> <body> <div class="lineSearch"> <ul> <li class="thRelative" id="hhDrop00"> <div class="boxSearch"> <span class="key_word"> <b class="size_14">北京</b> 出发城市 </span> <em class="ico thLeft ico_shBlue"></em> <a class="thRight ico btn_search" href="javascript:void(0)"></a> </div> <div class="search_form_suggest" style="display:none;"> <h3><a class="ico btn_close thRight" item="close">关闭</a>热门出发城市</h3> <dl class="search_hotList"> <dd class="clr_after"> <a href="#">北京</a> <a href="#">上海</a> <a href="#">广州</a> <a href="#">成都</a> <a href="#">杭州</a> <a href="#">南京</a> <a href="#">深圳</a> <a href="#">济南</a> <a href="#">石家庄</a> <a href="#">武汉</a> <a href="#">郑州</a> <a href="#">重庆</a> <a href="#">福州</a> <a href="#">西安</a> <a href="#">长沙</a> <a href="#">沈阳</a> <a href="#">天津</a> <a href="#">哈尔滨</a> <a href="#">苏州</a> <a href="#">南宁</a> </dd> </dl> <div class="clear"></div> </div> </li> <li class="thRelative" id="hhDrop01"> <div class="boxSearch"> <span class="key_word"> <b class="size_14">广州</b> 到达城市 </span> <em class="ico thLeft ico_shBlue"></em> <a class="thRight ico btn_search" href="javascript:void(0)"></a> </div> <div class="search_form_suggest" style="display:none;"> <h3><a class="ico btn_close thRight" item="close">关闭</a>热门出发城市</h3> <dl class="search_hotList"> <dd class="clr_after"> <a href="#">北京</a> <a href="#">上海</a> <a href="#">广州</a> <a href="#">成都</a> <a href="#">杭州</a> <a href="#">南京</a> <a href="#">深圳</a> <a href="#">济南</a> <a href="#">石家庄</a> <a href="#">武汉</a> <a href="#">郑州</a> <a href="#">重庆</a> <a href="#">福州</a> <a href="#">西安</a> <a href="#">长沙</a> <a href="#">沈阳</a> <a href="#">天津</a> <a href="#">哈尔滨</a> <a href="#">苏州</a> <a href="#">南宁</a> </dd> </dl> <div class="clear"></div> </div> </li> <li> <div class="thRelative lineSearchbg"> <em class="thLeft ico ico_serGray"></em> <input class="thLeft" name="textfield2" type="text" id="arriveSearchText" value="请输入目的地、主题或关键词" /> <a class="ico btn_close thLeft" item="close" style="margin:8px 8px 0 0;" id="btn_delete" >删除</a> <a class="ico btn_search" item="commit" href="javascript:void(0)">搜&nbsp;&nbsp;索</a> </div> </li> </ul> </div> </body> </html> ``` JS代码 ``` $(function(){ $.fn.hhDrop = function(options){ var options = jQuery.extend({ preLoadSrc:"images/loading.gif" }, options || {}); var defaults = {}; return this.each(function(){ //默认 var options = $.extend(defaults,options); var $this = $(this); var $boxSearch = $this.find('.boxSearch'); var $lineSearchbg = $this.nextAll().find('.lineSearchbg'); //出发城市 到达城市 $boxSearch.click(function(){ var _this = $(this); //点击本身显示隐藏 if(_this.hasClass('boxSearchHover') ){ _this.removeClass('boxSearchHover'); _this.children('.btn_search').removeClass('btn_search_current'); _this.parent().find('.search_form_suggest').hide(); }else{ _this.addClass('boxSearchHover'); _this.children('.btn_search').addClass('btn_search_current'); _this.parent().find('.search_form_suggest').show(); } _this.next().find('.clr_after a').click(function(){ _this.find('span.key_word b').text($(this).text()); }); _this.next().find('.search_city_result a').click(function(){ _this.find('span.key_word b').text($(this).text()); }); //阻止冒泡 $(document).bind('click',function(event){ if(!$(event.target).parent().hasClass('boxSearch' ) && !$(event.target).hasClass('boxSearch') && !$(event.target).parent().parent().hasClass('boxSearch') && !$(event.target).hasClass('input_city') ){ _this.children('.btn_search').removeClass('btn_search_current'); _this.removeClass('boxSearchHover'); _this.parent().find('.search_form_suggest').hide(); } }); }); $lineSearchbg.each(function(){ //搜索框 请输入目的地、主题或关键词 $(this).find('#arriveSearchText').focus(function(){ var arrive = $(this).val(); if(arrive == '请输入目的地、主题或关键词'){ $(this).val('').css('color','#000'); } }); $(this).find('#arriveSearchText').blur(function(){ var arrive = $(this).val(); if(arrive == ''){ $(this).val('请输入目的地、主题或关键词').css('color','#b5b5b5'); } }); //删除搜索信息 $(this).find('#btn_delete').click(function(){ $(this).prev('#arriveSearchText').focus().val('').css('color','#000'); }); }); }); } }); ``` 全部本地做好的了,可就是按钮没反应,是不是还需要改些什么啊?看过JS了,可里面没有提交搜索链接地址的地方啊

再次封装easyui datagrid 插件 Pagination分页的开启和关闭

js 具体代码如下 求大牛解答 (function($){ $.fn.data = function(options){ $.ajax({ //请求方式为get type: "GET", //xml文件位置 url: "data.xml", async: false, //返回数据格式为xml dataType: "xml", //请求成功完成后要执行的方法 success: function (data) { $(data).find('aaaa').each(function (i) { //读取xml文件,获取默认参数 //alert(12); var $item = $(this); pagin = $item.find('pagination').text(); pageL = $item.find('pageList').text(); rownu = $item.find('rownumbers').text(); pageS = $item.find('pageSize').text(); checkOnSelect = $item.find('checkOnSelect').text(); //alert(checkOnSelect); text = $item.find('text').text(); }) } }); $('#db').datagrid({ idField:'itemid', //标识字段 title:'数据列表', width:500, //height:300, url:'datagrid_data1.json', fitColumns:true, //自适应窗口 nowrap:true, //不显示在一行 striped:true, //各行换色 loadMsg:'数据加载中,请稍等...', //加载数据时提示的信息 rownumbers:rownu, //singleSelect:true, checkOnSelect:true, //点击行时复选框是否被选中 sortName:'sendTime', sortOrder:'desc', remoteSort:false, //scrollbarSize:200, rowStyler:function(index,data){ //console.info(index); //console.info(data); if(data.isGet==0){ //return 'background:silver'; }else{ //return 'background:green'; } }, columns:[[ {checkbox:true}, {field:'ck',title:'接收人',width:100}, {field:'productid',title:'内容',width:100}, {field:'listprice',title:'发送时间',width:100}, {field:'unitcost',tile:'cjkcs',width:100}, {field:'attr1',tile:'cjkcs',width:100}, {field:'status',tile:'cjkcs',width:100}, ]], pagination:pagin, pageSize:pageS, pageList:pageL, toolbar:[ {text:'增加',iconCls:'icon-add',handler:function(){ //alert('ok'); $("#register").dialog('open'); }}, { text:'删除', iconCls:'icon-remove', handler:function(){ var selects = $("#data").datagrid("getSelections"); //alert(selects.length); if(selects.length<=0){ $.messager.show({ title:'温馨提示', msg:'请选择要删除的记录' }); }else{ //将选中的记录删除(先找到每一个选中的元素) for(var i=0;i<selects.length;i++){ //alert(selects[i].messID); $.post("delete.php","id="+selects[i].messID,function(r){ //alert('ok'); $("#data").datagrid("reload"); }) } } } }, {text:'编辑',iconCls:'icon-edit'}, {text:'查询',iconCls:'icon-search'}, ], }); } } )(jQuery); xml 如下 <?xml version="1.0" encoding="utf-8"?> <aaaa> <pagination>false</pagination> <pageList>[1,2,3]</pageList> <rownumbers>true</rownumbers> <pageSize>5</pageSize> <checkOnSelect>true</checkOnSelect> <text>1</text>//默认是有,如果是0则关闭 </aaaa>

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

点沙成金:英特尔芯片制造全过程揭密

“亚马逊丛林里的蝴蝶扇动几下翅膀就可能引起两周后美国德州的一次飓风……” 这句人人皆知的话最初用来描述非线性系统中微小参数的变化所引起的系统极大变化。 而在更长的时间尺度内,我们所生活的这个世界就是这样一个异常复杂的非线性系统…… 水泥、穹顶、透视——关于时间与技艺的蝴蝶效应 公元前3000年,古埃及人将尼罗河中挖出的泥浆与纳特龙盐湖中的矿物盐混合,再掺入煅烧石灰石制成的石灰,由此得来了人...

上班一个月,后悔当初着急入职的选择了

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是HR所说那样,那个HR自...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

外包程序员的幸福生活

今天给你们讲述一个外包程序员的幸福生活。男主是Z哥,不是在外包公司上班的那种,是一名自由职业者,接外包项目自己干。接下来讲的都是真人真事。 先给大家介绍一下男主,Z哥,老程序员,是我十多年前的老同事,技术大牛,当过CTO,也创过业。因为我俩都爱好喝酒、踢球,再加上住的距离不算远,所以一直也断断续续的联系着,我对Z哥的状况也有大概了解。 Z哥几年前创业失败,后来他开始干起了外包,利用自己的技术能...

C++11:一些微小的变化(新的数据类型、template表达式内的空格、nullptr、std::nullptr_t)

本文介绍一些C++的两个新特性,它们虽然微小,但对你的编程十分重要 一、Template表达式内的空格 C++11标准之前建议在“在两个template表达式的闭符之间放一个空格”的要求已经过时了 例如: vector&lt;list&lt;int&gt; &gt;; //C++11之前 vector&lt;list&lt;int&gt;&gt;; //C++11 二、nullptr ...

优雅的替换if-else语句

场景 日常开发,if-else语句写的不少吧??当逻辑分支非常多的时候,if-else套了一层又一层,虽然业务功能倒是实现了,但是看起来是真的很不优雅,尤其是对于我这种有强迫症的程序"猿",看到这么多if-else,脑袋瓜子就嗡嗡的,总想着解锁新姿势:干掉过多的if-else!!!本文将介绍三板斧手段: 优先判断条件,条件不满足的,逻辑及时中断返回; 采用策略模式+工厂模式; 结合注解,锦...

深入剖析Springboot启动原理的底层源码,再也不怕面试官问了!

大家现在应该都对Springboot很熟悉,但是你对他的启动原理了解吗?

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

为什么你不想学习?只想玩?人是如何一步一步废掉的

不知道是不是只有我这样子,还是你们也有过类似的经历。 上学的时候总有很多光辉历史,学年名列前茅,或者单科目大佬,但是虽然慢慢地长大了,你开始懈怠了,开始废掉了。。。 什么?你说不知道具体的情况是怎么样的? 我来告诉你: 你常常潜意识里或者心理觉得,自己真正的生活或者奋斗还没有开始。总是幻想着自己还拥有大把时间,还有无限的可能,自己还能逆风翻盘,只不是自己还没开始罢了,自己以后肯定会变得特别厉害...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发(16k)

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

【阿里P6面经】二本,curd两年,疯狂复习,拿下阿里offer

二本的读者,在老东家不断学习,最后逆袭

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

《经典算法案例》01-08:如何使用质数设计扫雷(Minesweeper)游戏

我们都玩过Windows操作系统中的经典游戏扫雷(Minesweeper),如果把质数当作一颗雷,那么,表格中红色的数字哪些是雷(质数)?您能找出多少个呢?文中用列表的方式罗列了10000以内的自然数、质数(素数),6的倍数等,方便大家观察质数的分布规律及特性,以便对算法求解有指导意义。另外,判断质数是初学算法,理解算法重要性的一个非常好的案例。

《Oracle Java SE编程自学与面试指南》最佳学习路线图(2020最新版)

正确选择比瞎努力更重要!

面试官:你连SSO都不懂,就别来面试了

大厂竟然要考我SSO,卧槽。

微软为一人收购一公司?破解索尼程序、写黑客小说,看他彪悍的程序人生!...

作者 | 伍杏玲出品 | CSDN(ID:CSDNnews)格子衬衫、常掉发、双肩包、修电脑、加班多……这些似乎成了大众给程序员的固定标签。近几年流行的“跨界风”开始刷新人们对程序员的...

终于,月薪过5万了!

来看几个问题想不想月薪超过5万?想不想进入公司架构组?想不想成为项目组的负责人?想不想成为spring的高手,超越99%的对手?那么本文内容是你必须要掌握的。本文主要详解bean的生命...

我说我懂多线程,面试官立马给我发了offer

不小心拿了几个offer,有点烦

自从喜欢上了B站这12个UP主,我越来越觉得自己是个废柴了!

不怕告诉你,我自从喜欢上了这12个UP主,哔哩哔哩成为了我手机上最耗电的软件,几乎每天都会看,可是吧,看的越多,我就越觉得自己是个废柴,唉,老天不公啊,不信你看看…… 间接性踌躇满志,持续性混吃等死,都是因为你们……但是,自己的学习力在慢慢变强,这是不容忽视的,推荐给你们! 都说B站是个宝,可是有人不会挖啊,没事,今天咱挖好的送你一箩筐,首先啊,我在B站上最喜欢看这个家伙的视频了,为啥 ,咱撇...

立即提问
相关内容推荐