【问题标题】:How to retrieve an input element and its surrounded span?如何检索输入元素及其包围的跨度?
【发布时间】:2009-10-07 12:59:06
【问题描述】:

对于

<span id="" ...>
  <input id="" ...>

有什么方法可以检索 span id?输入元素嵌入跨度?

【问题讨论】:

    标签: javascript input html


    【解决方案1】:
    document.getElementById("inputId").parentNode;
    

    【讨论】:

      【解决方案2】:

      如果您使用的是 jQuery:

      $('#input-id').parent().attr('id');
      

      如果没有:

      document.getElementById('input-id').parentNode.getAttribute('id');
      

      编辑:哎呀 - 在 parentNode 之后删除了多余的括号!

      【讨论】:

        【解决方案3】:
        var parentControl = document.getElementByID("id goes here").parentNode;
        

        【讨论】:

          猜你喜欢
          • 2012-08-23
          • 2013-01-10
          • 1970-01-01
          • 2018-10-04
          • 1970-01-01
          • 2021-10-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多