<i id='o7vhN'><tr id='o7vhN'><dt id='o7vhN'><q id='o7vhN'><span id='o7vhN'><b id='o7vhN'><form id='o7vhN'><ins id='o7vhN'></ins><ul id='o7vhN'></ul><sub id='o7vhN'></sub></form><legend id='o7vhN'></legend><bdo id='o7vhN'><pre id='o7vhN'><center id='o7vhN'></center></pre></bdo></b><th id='o7vhN'></th></span></q></dt></tr></i><div id='o7vhN'><tfoot id='o7vhN'></tfoot><dl id='o7vhN'><fieldset id='o7vhN'></fieldset></dl></div>

    1. <small id='o7vhN'></small><noframes id='o7vhN'>

      • <bdo id='o7vhN'></bdo><ul id='o7vhN'></ul>
      <tfoot id='o7vhN'></tfoot>

      1. <legend id='o7vhN'><style id='o7vhN'><dir id='o7vhN'><q id='o7vhN'></q></dir></style></legend>
      2. foreach 相当于 jquery 中的 php?

        时间:2023-09-21

        <small id='i4In7'></small><noframes id='i4In7'>

          <legend id='i4In7'><style id='i4In7'><dir id='i4In7'><q id='i4In7'></q></dir></style></legend>
            <i id='i4In7'><tr id='i4In7'><dt id='i4In7'><q id='i4In7'><span id='i4In7'><b id='i4In7'><form id='i4In7'><ins id='i4In7'></ins><ul id='i4In7'></ul><sub id='i4In7'></sub></form><legend id='i4In7'></legend><bdo id='i4In7'><pre id='i4In7'><center id='i4In7'></center></pre></bdo></b><th id='i4In7'></th></span></q></dt></tr></i><div id='i4In7'><tfoot id='i4In7'></tfoot><dl id='i4In7'><fieldset id='i4In7'></fieldset></dl></div>

                <tbody id='i4In7'></tbody>
              <tfoot id='i4In7'></tfoot>
                  <bdo id='i4In7'></bdo><ul id='i4In7'></ul>
                  本文介绍了foreach 相当于 jquery 中的 php?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  JQuery 中有没有像 PHP 一样的 foreach 代码?我在 php 中有一个代码,比如

                  Is there a foreach code in JQuery as in PHP? I have a code in php,like

                  <?php foreach ($viewfields as $viewfield): ?>       
                  if("<?php echo $viewfield['Attribute']['required'];?>"=='true'){
                         $("<span class='req'><em> * </em></span>").appendTo("#fb_contentarea_col1down21 #label<?php echo $viewfield['Attribute']['sequence_no']?>");
                     }
                  
                  
                     if(<?=$viewfield['Attribute']['type'];?>=='text'||<?=$viewfield['Attribute']['type'];?>=='date'||<?=$viewfield['Attribute']['type'];?>=='number'){ 
                         $("<input id=input<?=$viewfield['Attribute']['sequence_no'];?> type= 'text' style= 'width:<?=$viewfield['Attribute']['size'];?>px' data-attr=<?=$viewfield['Attribute']['type'];?> ></input><br>").appendTo("#fb_contentarea_col1down21 #<?=$viewfield['Attribute']['sequence_no'];?>");
                     }
                  
                  
                     else if(<?=$viewfield['Attribute']['type'];?>=='textarea'){
                         $("<textarea style= 'width:<?=$viewfield['Attribute']['size'];?>px' data-attr=<?=$viewfield['Attribute']['type'];?> id=input<?=$viewfield['Attribute']['sequence_no'];?>></textarea><br>").appendTo("#fb_contentarea_col1down21 #<?=$viewfield['Attribute']['sequence_no'];?>");
                  }
                  

                  在 Jquery 中是否有任何等效的 foreach?如何在 jQuery 中实现同样的功能?

                  Is there any equivalent of foreach in Jquery? How can I accomplish this same functioality in jQuery?

                  编辑 1:

                  我认为它有效,但出现错误.代码和错误信息如下.

                  I thought it worked but I get an error. The code and the error message is given below.

                  for(<?=$viewfield;?> in <?=$viewfields;?>){
                  
                   if("<?=$viewfield['Attribute']['required'];?>"=='true'){
                              $("<span class='req'><em> * </em></span>").appendTo("#fb_contentarea_col1down21 #label<?php echo $viewfield['Attribute']['sequence_no']?>");
                   }
                  
                   if(<?=$viewfield['Attribute']['type'];?>=='text'||<?=$viewfield['Attribute']['type'];?>=='date'||<?=$viewfield['Attribute']['type'];?>=='number'){ 
                              $("<input id=input<?=$viewfield['Attribute']['sequence_no'];?> type= 'text' style= 'width:<?=$viewfield['Attribute']['size'];?>px' data-attr=<?=$viewfield['Attribute']['type'];?> ></input><br>").appendTo("#fb_contentarea_col1down21 #<?=$viewfield['Attribute']['sequence_no'];?>");
                   }
                  
                   else if(<?=$viewfield['Attribute']['type'];?>=='textarea'){
                              $("<textarea style= 'width:<?=$viewfield['Attribute']['size'];?>px' data-attr=<?=$viewfield['Attribute']['type'];?> id=input<?=$viewfield['Attribute']['sequence_no'];?>></textarea><br>").appendTo("#fb_contentarea_col1down21 #<?=$viewfield['Attribute']['sequence_no'];?>");
                   }
                  

                  }

                  错误信息:

                  语法错误for(在数组中)

                  syntax error for( in Array)

                  谁能帮我..

                  推荐答案

                  $.each 功能类似.

                  它允许您使用可以访问每个项目的回调函数迭代数组:

                  It allows you to iterate arrays using a callback function where you have access to each item:

                  var arr = [ "one", "two", "three", "four", "five" ];
                  
                  
                  $.each(arr, function(index, value) {
                    // work with value
                  });
                  

                  知道也许有用,如果你想打破循环,你可以用 return false; 或者如果你只想跳过一次迭代(继续),你 return真;

                  Maybe is useful to know, if you want to break the loop, you can do it with return false; or if you want to skip only one iteration (continue), you return true;

                  这篇关于foreach 相当于 jquery 中的 php?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:php使用foreach将值插入数组中 下一篇:借助 PHP 和 HTML 动态创建行和列

                  相关文章

                  最新文章

                  1. <tfoot id='uGYTQ'></tfoot>
                    • <bdo id='uGYTQ'></bdo><ul id='uGYTQ'></ul>

                    <i id='uGYTQ'><tr id='uGYTQ'><dt id='uGYTQ'><q id='uGYTQ'><span id='uGYTQ'><b id='uGYTQ'><form id='uGYTQ'><ins id='uGYTQ'></ins><ul id='uGYTQ'></ul><sub id='uGYTQ'></sub></form><legend id='uGYTQ'></legend><bdo id='uGYTQ'><pre id='uGYTQ'><center id='uGYTQ'></center></pre></bdo></b><th id='uGYTQ'></th></span></q></dt></tr></i><div id='uGYTQ'><tfoot id='uGYTQ'></tfoot><dl id='uGYTQ'><fieldset id='uGYTQ'></fieldset></dl></div>

                    1. <small id='uGYTQ'></small><noframes id='uGYTQ'>

                    2. <legend id='uGYTQ'><style id='uGYTQ'><dir id='uGYTQ'><q id='uGYTQ'></q></dir></style></legend>