Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我有一些 JQuery 对象$("#someDiv"),它的 html(),
$("#someDiv")
$("#someDiv").html();
等于:
<div id="bla_i"> <input ... id="ble_i" /> </div>
(即:很多嵌套元素,其中一些具有包含“_i”的 id 和名称)
我怎样才能使所有这些 "_i" 成为 "_5" ? 如何替换某些 JQuery 对象中的所有“_i”?
var html = $('#someDiv').html(); // get the html string $(html) // make jQuery object .find('[id*="_i"]') // find elements with id contains "_i" .attr('id',function(i, oldId) { return oldId.replace('_i', '_5'); // replace all "_i" with "_5" });