如何获取AngularJs中元素父级的ID

时间:2017-02-06 07:32:18

标签: angularjs element parent

在下面的代码中:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="filter check-brand">
    <div id="devicebrand" class="wrapper-dropdown-3" tabindex="1">
      <i class="icon icon-brand"></i>
      <span data-val="-1">check brand </span>
      <div class="dropdown brand">
        <span class="icon-cross-it"></span>
        <div class="side-info">
          <p class="SELECT-YOUR-MOBILE-P">SELECT YOUR MOBILE BRAND  </p>
          <p class="One-line-to-explain">One line to explain why he needs to select his city. Along with more information.</p>
        </div>
        <div class="city-selection">
          <ul>
            <li><span class="icon-oval-3-copy-3"></span><a href="#" data-val="htc">HTC</a></li>
            <li><span class="icon-oval-3-copy-3"></span><a href="#" data-val="motorola">motorola</a></li>
            <li><span class="icon-oval-3-copy-3"></span><a href="#" data-val="xiaomi">xiaomi</a></li>
            <li><span class="icon-oval-3-copy-3"></span><a href="#" data-val="lg">LG</a></li>
            <li><span class="icon-oval-3-copy-3"></span><a href="#" data-val="samgsung">samgsung</a></li>
            <li><span class="icon-oval-3-copy-3"></span><a href="#" data-val="sony">sony</a></li>
            <li><span class="icon-oval-3-copy-3"></span><a href="#" data-val="huawei">huawei</a></li>
            <li><span class="icon-oval-3-copy-3"></span><a href="#" data-val="google pixel">google pixel</a></li>
            <li><span class="icon-oval-3-copy-3"></span><a href="#" data-val="nokia">nokia</a></li>
            <li><span class="icon-oval-3-copy-3"></span><a href="#" data-val="le-eco">le-eco</a></li>
          </ul>
          <div class="more-brands">
            <a class="more-brands-btn" href="javascript:void(0);">+ 254 Brands</a>
          </div>
          <div class="manual-brand">
            <input placeholder="Enter your brand if not found above " id="manual-brand-input" class="manual-brand-input ui-autocomplete-input" value="" autocomplete="off" type="text"><span class="icon-shape_4"></span>
          <ul id="ui-id-1" tabindex="0" class="ui-menu ui-widget ui-widget-content ui-autocomplete ui-front" style="display: none;"></ul></div>
          <div class="covered hidden">
            <p><span class="icon-tick"></span>Congratulations! Free Pick &amp; Drop service available in your city</p>
            <p><span class="icon-tick"></span>400 Service centers near you</p>
            <p><span class="icon-tick"></span>20% of people bought this near your locality</p>
            <p><span class="icon-tick"></span>3days is average repair time in your area.</p>
          </div>
          <div class="not-covered hidden">
            <p><span class="icon-not-covered-tick"></span>Sorry, we are currently present in India. We don’t cover your City.</p>
            <p>We can briefly state here why we dont cover particular city. Or if at all we are in process of including it.</p>
          </div>
        </div>
      </div>
      <i class="icon-down-arrow-1"></i>
      <i class="icon-orange-cross hidden"></i>
    </div>
  </div>

如何访问父母的身份证?如果我这样做的话:

   angular.element(element).parent()

控制台告诉我:

enter image description here

1 个答案:

答案 0 :(得分:2)

使用.attr() / .prop()方法

angular.element(element).parent().attr('id')