var str = "<a alt="Complaint ID" class="filterTag"
href="javascript:void(0)">0005000003</a>"
var result = "Complaint ID"
我想在上面的字符串
中提取锚标记的alt值答案 0 :(得分:0)
您可以使用Jquery:
$('<a alt="Complaint ID" class="filterTag" href="javascript:void(0)">0005000003</a>').attr("alt")
或者你可以用飞机JS做到这一点:
var xmlString = '<a alt="Complaint ID" class="filterTag" href="javascript:void(0)">0005000003</a>'
, parser = new DOMParser()
, doc = parser.parseFromString(xmlString, "text/xml");
console.log(doc.firstChild.getAttribute("alt"));
答案 1 :(得分:0)
您可以使用JQuery将HTML内容字符串作为元素选择器,然后使用alt
attr()
的值
var str = '<a alt="Complaint ID" class="filterTag" href="javascript:void(0)">0005000003 </a>';
var alt = $(str).attr('alt');
console.log(alt);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>