【问题标题】:Get HTML of anchor tag with onclick event [duplicate]使用 onclick 事件获取锚标记的 HTML [重复]
【发布时间】:2020-05-06 19:36:22
【问题描述】:

我正在尝试获取整个锚标记的 html,但它只返回 <span> 标记 html。我错过了什么?

getDetails = function (ord_id) {
                var $a = $('a[data-ord_id^=' + ord_id + ']');
                console.log($a.html());            
};    

 <a aria-role="button" class="boxSizing" data-businesslocaltime="05/05/2020 11:32 PM" data-business_id="1" data-completedstage="0" data-deferdue="5/5/2020 11:17:27 PM" data-ord_id="462724" data-refnum="R60152" data-timestamp="5/5/2020 10:32:40 PM" onclick="getDetails('462724','0');" role="listitem"><span class="material-icons boxSizing"></span><span class="ordtype boxSizing">Pick Up</span><span class="ordtime boxSizing"> placed @ 11:32 PM, May 05 2020</span></a>

结果

<span class="material-icons boxSizing"></span><span class="ordtype boxSizing"></span><span class="ordtime boxSizing"> placed @ 04:12 PM, May 05 2020</span>

【问题讨论】:

标签: jquery


【解决方案1】:

成功了,

var $a = $('[data-ord_id^=' + ord_id + ']');
console.log($a.get(0).outerHTML);

【讨论】:

    猜你喜欢
    • 2011-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-19
    • 1970-01-01
    • 1970-01-01
    • 2014-12-22
    相关资源
    最近更新 更多