简体   繁体   English

无法从字符串集合中找到href标记

[英]Not able to find the href tag from string collection

here is my code.... 这是我的代码。

   $(lines[i]).find('[href]').each(function () {
        checkLinkFooter = true;
        footerLinks += $(this).attr('href') + '~';
        });                   And my string is : If you prefer not to receive, reply to   the sender or        contact us at <a target="_blank" href="mailto:tmcustomerresponse@agi.com" style="font-weight:bold;text-decoration:none;color:#0085d5">tmcustomerresponse@agi.com</a>. Getting console error " Syntax error, unrecognized expression:"

You need to wrap your string with another dom object to use .find() . 您需要使用另一个dom对象包装字符串以使用.find()

Now you have a string starting with a word, so jQuery will consider it as a selector, but since it contains invalid characters, it might throw an error saying something like Uncaught Error: Syntax error, unrecognized expression: hi <a> . 现在您有了一个以单词开头的字符串,因此jQuery会将其视为选择器,但是由于它包含无效字符,它可能会抛出错误,提示诸如Uncaught Error: Syntax error, unrecognized expression: hi <a>

$('<div />', {
    html: lines[i]
}).find('[href]').each(function () {
    checkLinkFooter = true;
    footerLinks += $(this).attr('href') + '~';
});

Demo: Fiddle 演示: 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM