<xml xmlns="http://www.w3.org/1999/xhtml">
<block type="variables_get" id="EaezE9)%*e^B{Olq7?Le" x="147" y="34"></block>
</xml>
請問如何獲取這段字符串中的id?額,這是一段字符串
認(rèn)證0級講師
正則的話,試一下用match,其實也就是要識別到字符串 id="EaezE9)%*e^B{Olq7?Le"
,然后提取出引號里面的字符串
var t = `<xml xmlns="http://www.w3.org/1999/xhtml">
<block type="variables_get" id="EaezE9)%*e^B{Olq7?Le" x="147" y="34"></block>
</xml>`;
var res = t.match(/id\s*="([^"]*)"/);
console.log(res&&res[1])
var span = document.createElement("span");
span.innerHTML = `<xml xmlns="http://www.w3.org/1999/xhtml">
<block type="variables_get" id="EaezE9)%*e^B{Olq7?Le" x="147" y="34"></block>
</xml>`;
var block= span.getElementsByTagName('block')[0];
var id = block.getAttribute("id");
var str='<xml xmlns="http://www.w3.org/1999/xhtml"><block type="variables_get" id="EaezE9)%*e^B{Olq7?Le" x="147" y="34"></block></xml>';
var reg = /.*id\=\"([^ \"]*).*/gi;
reg.exec(str)[1];
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號