我试图在更改为input. 但是,该函数仅在搜索的第一个字母上工作正常,并且<strong></strong>在有多个字符串匹配时不会将 加到字符串中。我尝试keyup使用以下任何解决方案解开匹配的字符串以将强字符串重新应用于匹配的字符串,但这也不起作用:$("button").find('strong').unwrap('strong');$("button").children().unwrap('strong');$("button").children().find('strong').unwrap();$("input").on('keyup', function() { // $("button").find('strong').unwrap('strong'); // $("button").children().unwrap('strong'); // $("button").children().find('strong').unwrap(); var boldLetter = $("input").val(); $("button").html(function(_, html) { return html.replace(new RegExp(boldLetter, 'gi'), '<strong>$&</strong>'); });});<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>Enter Search Word: <input type="text"><br /><br /><button type="button">Afghanistan</button><button type="button">Antarctica</button><button type="button">Mali</button><button type="button">Canada</button><button type="button">US</button><button type="button">France</button><button type="button">Chile</button><button type="button">Peru</button>
添加回答
举报
0/150
提交
取消