Tag: 循环

我的setTimeout无法正常工作

这是代码: var stripeAnimation = function() { var streetDivWidth = $(‘.street_name’).width(); var streetFull = $(‘.street_name .street_name_text’); for(var i=0; i<streetFull.length; i++) { var item = $(streetFull[i]); var widthFull = item.width(); var remainder = widthFull – streetDivWidth; var animationSpeed = widthFull * 5; var summary = streetDivWidth – widthFull; if(summary < 0) { item.children('.gradient_span').addClass('gradient'); infinite(); setTimeout(infinite, 1000); } […]

jQuery eq()循环

你能帮我这个吗? $(document).ready(function(){ $(“ul.fam:eq(0) li:eq(2)”).addClass(“redbold”); }); 在这段代码中,有没有办法在 – > $中循环或递增’0’值(“ul.fam:eq(0)?就像使它成为0,1,2,3,4,5等等。 ..并在例如达到’3’时停止循环 谢谢。

将上一个/下一个按钮添加到针对DIVS的水平内容滚动条

我已经为div上的一些滚动实现了jQuery Custom Scroller ,这非常有用。 我甚至使用平滑滚动来水平滚动到某些DIV但我的问题是我想要一个下一个和上一个导航按钮,我无法在任何地方找到它。 下面是我的HTML和jQuery。 先谢谢 the cedarburg CSS: #source-container{ overflow-x: hidden; overflow-y: hidden; } .source-item{ float: left; display: inline-block; background-repeat:no-repeat; background-size:cover; background-position: center; -moz-background-size: cover; } #source-container .one{background-image:url(images/source/1-the-cedarberg.jpg);} #source-container .two{background-image:url(images/source/2-the-cedarberg.jpg);} #source-container .three{background-image:url(images/source/3-the-cedarberg.jpg);} #source-container .four{background-image:url(images/source/4-the-cedarberg.jpg);} #source-container .five{background-image:url(images/source/5-the-cedarberg.jpg);} #source-container .six{background-image:url(images/source/6-the-cedarberg.jpg);} #source-container .seven{background-image:url(images/source/2-our-farm.jpg);} #source-container .eight{background-image:url(images/source/1-our-farm.jpg);} #source-container .nine{background-image:url(images/source/3-our-farm.jpg);} #source-container .ten{background-image:url(images/source/4-our-farm.jpg);} #source-container .eleven{background-image:url(images/source/1-our-rooibos.jpg);} #source-container .twelve{background-image:url(images/source/6-the-cedarberg.jpg);} #source-container .thirteen{background-image:url(images/source/1-the-cedarberg.jpg);} #source-container […]

需要为插件的每个.post获取’a’名称

(function ($) { ‘use strict’; var url = window.location.href.split(‘#’)[0]; var post = $(‘.post’).children(‘a[name]’).attr(‘name’); var helpers = { “defaults”: { “post”: post, “href”: url+’#’, “send”: ‘true’, “layout”: ‘button_count’, “width”: ‘125’, “faces”: ‘false’, “font”: ‘verdana’, “action”: ‘like’, “scheme”: ‘light’, }, “init”: function (options) { var settings = $.extend({}, helpers.defaults, options), easyface = $(”).addClass(‘easyface fb-like’).attr({ “data-href”: settings.href + […]

尝试将两个跨度与jQuery结合在一起,需要帮助循环/迭代

我认为这是一个非常棒的问题,但我现在已经考虑了好几个小时了,我无法弄明白。 我需要在下面使用这个html代码并获取.project_name span和.location span以合并到同一个span中。 First Project Name Combined with First Location Second Project Name Combined with Second Location Third Project Name Combined with Third Location ​ 我有这个jQuery代码,它将正确地执行第一组跨度,但将继续使用第一个span的内容来填充其余的。 var s1 = $(‘.project_name’).html(); $(‘.project_name’).remove(); $(‘.location’).prepend(s1 + ‘ ‘); 我假设我需要使用.each()或类似的东西,但我无法弄清楚正确的语法使它工作。 这是我迄今为止所拥有的jsFiddle 。 有任何想法吗? 这可能很简单。

变量和jquery:如何捕获值并使用它们(第2部分)

这是我的问题: 我从ul-li列表中捕获了一个变量 我有一个名单很多的名单: 罗马,米兰,威尼斯…我用鼠标hover事件捕捉这些(罗马的pulsante1,米兰的pulsante2,威尼斯的pulsante3,……)的id值(寻找这个)问题变量和jquery:如果你想了解更多, 如何捕获值(第1部分 )。 所以,我现在有一个名为$ regionMap的全局变量,每次ul-li列表都有mouseover事件时,它的内容会发生变化。 所以,现在我可以在其他jquery脚本中使用$ regionMap值而不是不同的id值( pulsante1,pulsante2,pulsante3 …… )。 例如,我有这个循环: $(‘#pulsante1’).mousedown(function() // when click over pulsante1 (id value for “Roma”) { var $variab=document.getElementById(‘pulsante1’).innerHTML; // take the name (here Roma) var $alfa=”#”+ $variab; // Roma is now #Roma alert(“You entered: ” + $alfa); //control dialog($alfa); // calling the function dialog rolling on […]

Thymeleaf,Javascript内联和迭代

使用Spring MVC和Thymeleaf,我正在构建一个带有一些javascript的html视图。 在页面内,th:每个都与迭代值一起使用,为一组按钮提供唯一的HTML id。 我的问题来自于尝试生成javascript,它将使用jQuery引用到每个按钮id。 在“另一种”视图分辨率语言中,我会使用代码: <% for(var i = 0; i $(‘#optionBtn_’).on(“click”, function() { doSomething(”); }); (以上可能不是100%语法正确,但我希望你能得到这个想法 – 我正在尝试做的是使用上述风格) 但在Thymeleaf,虽然我明白我可以使用 th:inline=”javascript” 为了引用单个模型项,我无法看到如何在脚本块中使用外观生成多个jQuery函数调用定义。 有任何想法吗? (我可能完全错误地解决了这个问题,所以我也对这方面的新想法持开放态度)

将特定的php变量从循环中获取到jquery函数参数

我有一个自动建议文本框女巫生成带有函数的onclick事件的li标签但我必须将php变量传递给函数作为参数但我只想要用户点击的li的变量值现在我总是得到循环中的最后一个变量。 我希望var测试值为$ test = $ row [‘t_product’]; 用户点击的li 这是现在使用的代码: if(isset($_POST[‘search_term’]) == true && empty($_POST[‘search_term’]) == false){ $search_term = $_POST[‘search_term’]; $customerid = $_SESSION[‘userdata’][‘t_customer_id’]; $conn = connect(); $sql = “SELECT * FROM Licenses WHERE customer_id = ‘$customerid’ AND t_name LIKE ‘$search_term%'”; $query = sqlsrv_query($conn, $sql); while(($row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)) != false){ $test = $row[‘t_product’]; ?> var test […]

如何在while循环中使用jquery显示/隐藏表行

所以我有一个使用while循环从数据库生成的表。 数据以行显示。 重点是有“隐藏”行,数据仅在点击时可用(如显示详细信息)。 基本上我想要这样的东西: http : //www.transfercar.co.nz/ – 如果你点击表格行,下面会显示更多数据(在新行中)。 我的代码如下所示: while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { $display1=$display1+1; echo ‘ ‘ . $row[‘id’] . ‘ ‘ . $row[‘name’] . ‘ ‘ . $row[‘surname’] . ‘ ‘ . $row[‘country’] . ‘ ‘ . $row[‘city’] . ‘ ‘ . $row[‘category’] . ‘ ‘; if($row[‘id’]==$_GET[‘showrow’]) { echo ‘ ‘; […]

for循环之后的多个元素的jQuery append(),而不是展平为HTML

我有一个循环: for (index = 0; index < total_groups; index += 1) { groups[index].list_item = $(list_item_snippet); // Closure to bind the index for event handling (function (new_index) { groups[index].list_item.find('.listing-group-title') .html(groups[index].Group.Name) .click(function(e){ fns.manageActiveGroup(new_index, groups); return false; }); })(index); // Append to DOM mkp.$group_listing.append(groups[index].list_item); }; 每次循环触发时我宁愿不调用append() 。 我知道我可以使用String并将标记与每个循环迭代连接mkp.$group_listing并在最后将字符串附加到mkp.$group_listing ,但是这会使对象变平并且绑定会丢失(我不依赖于ID)。 有没有办法可以将我的对象添加到数组中并将它们全部一次性地附加到底部而不会转换为HTML? 假设: $(list_item_snippet)包含一些定义列表项的HTML(并包含一个类为.listing-group-title的元素)。 groups是我的脚本中定义“组”的JSON块 封闭效果很好 编辑: 发现我可以使用以下语法追加多个元素: mkp.$group_listing.append(groups[0].list_item, groups[1].list_item […]