【问题标题】:How do you read inner element values in a div according to main div?如何根据主 div 读取 div 中的内部元素值?
【发布时间】:2011-12-10 09:05:53
【问题描述】:

我想根据MainContainer div读取每个div(refer0和refer1)中select and textarea elements的每个值。 refer0 and refer1 将动态创建运行时,我不知道他们的 ID。但MainContainer div element 是静态的。

  <div id="MainContainer">

    <div id="Rfer0">
    <select id="LstRefer0" >
    <option value="52">a</option>
    <option value="116">b</option>
    </select>
    <textarea class="textbox" id="Area0" readonly="readonly" cols="20" rows="2" ></textarea>
    </div>

    <div id="Rfer1">
    <select id="LstRefer1" >
    <option value="52">a</option>
    <option value="116">b</option>
    </select>
    <textarea class="textbox" id="Area1" readonly="readonly" cols="20" rows="2" ></textarea>
    </div>


    </div>

【问题讨论】:

    标签: jquery


    【解决方案1】:

    我现在在我的 iPad 上,所以我无法测试代码,但假设你使用的是 jquery,它应该是这样的

    $('option').each(function() {
       alert( $(this).val() );
    });
    
    $('textarea').each(function() {
       alert( $(this).val() );
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-27
      • 2018-02-12
      • 1970-01-01
      • 2017-12-04
      • 1970-01-01
      • 1970-01-01
      • 2021-11-01
      • 2014-02-20
      相关资源
      最近更新 更多