【问题标题】:Retrieve input from specific div从特定 div 检索输入
【发布时间】:2012-06-08 07:37:56
【问题描述】:

我目前有多个对话框,但我想保持元素“名称”原样,以便我可以在一个函数中处理它。

代码:

    <div class="hiddenInViewSource" id="dialog-properties-section" title="Control Properties">
        <div id="tabs-section">
            <ul>
                <li><a href="#tabs-section-basic">Basic</a></li>
            </ul>
            <div id="tabs-section-basic">
                Section Caption <br/><input type="text" name="label" /><br/>
                Section Introduction <br/><input type="text" name="additionalLabel" /><br/><br/>

                <br/><br/>

                <button>Save</button>
                <button>Cancel</button>
            </div>
        </div>
    </div>

    <div class="hiddenInViewSource" id="dialog-properties-simple" title="Control Properties">
        <div id="tabs-simple">
            <ul>
                <li><a href="#tabs-simple-basic">Basic</a></li>
            </ul>
            <div id="tabs-simple-basic">
                simple Caption <br/><input type="text" name="label" /><br/>

                <br/><br/>

                <button>Save</button>
                <button>Cancel</button>
            </div>
        </div>
    </div>

现在我检索标签的值,例如:

 $('[name=label]').val();

当然,现在它不知道应该从哪个 div 获取它,它返回空。 (因为只填了 1 会得到错误的。)

我的问题:

如何使用选择器从正确的 div 中检索输入值?

【问题讨论】:

    标签: jquery html forms jquery-selectors dialog


    【解决方案1】:

    在选择器中使用主包装器的 ID

      alert( $('#tabs-simple input[name=label]').val() );
    

    【讨论】:

      【解决方案2】:
      $('#tabs-section-basic input[name=label]').val();
      
      $('#tabs-simple-basic input[name=label]').val();
      

      【讨论】:

        【解决方案3】:

        $('#tabs-simple input[name=label]').val();

        【讨论】:

        • 没问题,我以为我错过了什么。 (可能是,毕竟是星期一。)感谢您的快速回复。 :)
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-06-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多