如何在JS中遍历数组?

时间:2018-09-09 11:58:26

标签: javascript php ajax

我有个小问题。我发出了一个Ajax请求,并收到了一个数组形式的ancver,我想在JS上遍历它(如PHP上的foreach()),并在准备好的html元素中使用它的内容:

<div class="price">
            $9<span>/Month</span>                          
          </div>
          <ul>
            <li>Free Setup</li>
            <li>10GB Storage</li>
            <li>100GB Bandwith</li>
            <li>5 Products</li>
          </ul>
          <a href="#" class="btn btn-lg btn-primary">Sign up</a>
        </div>
      </div>
      <div class="col-sm-3">
        <div class="single-table wow flipInY" data-wow-duration="1000ms" data-wow-delay="500ms">
          <h3>Standard</h3>
          <div class="price">
            $19<span>/Month</span>                                
          </div>
          <ul>
            <li>Free Setup</li>
            <li>10GB Storage</li>
            <li>100GB Bandwith</li>
            <li>5 Products</li>
          </ul>
          <a href="#" class="btn btn-lg btn-primary">Sign up</a>
        </div>
      </div>
      <div class="col-sm-3">
        <div class="single-table featured wow flipInY" data-wow-duration="1000ms" data-wow-delay="800ms">
          <h3>Featured</h3>
          <div class="price">
            $29<span>/Month</span>                                
          </div>
          <ul>
            <li>Free Setup</li>
            <li>10GB Storage</li>
            <li>100GB Bandwith</li>
            <li>5 Products</li>
          </ul>
          <a href="#" class="btn btn-lg btn-primary">Sign up</a>
        </div>
      </div>
      <div class="col-sm-3">
        <div class="single-table wow flipInY" data-wow-duration="1000ms" data-wow-delay="1100ms">
          <h3>Professional</h3>
          <div class="price">
            $49<span>/Month</span>                    
          </div>
          <ul>
            <li>Free Setup</li>
            <li>10GB Storage</li>
            <li>100GB Bandwith</li>
            <li>5 Products</li>
          </ul>
          <a href="#" class="btn btn-lg btn-primary">Sign up</a>
        </div>
      </div>
    </div>  

我有一个按钮,当单击按钮时,向php发送了ajax请求,并且php处理了来自ajax请求的数据,并返回了数组。我想将上面写的HTML中的数组中的数据放置在HTML中,并将其与html一起显示在页面中

如何在脚本中添加html标签。以及如何实现它。谢谢!

0 个答案:

没有答案