var d = a piece of html, got it from the server;
//I want to do this to the html from "d"
$('#ls li .ae-lookup-mbtn').prepend("<a href='#' title='+' class='ui-icon <%=ai%>'>+</a>");发布于 2011-01-05 16:10:57
var d = '<!-- your HTML string -->';
var $d = $(d); // create a new jQuery object, passing it the HTML string
// perform a find() on the resulting jQuery object, and do your prepend
$d.find('#ls li .ae-lookup-mbtn').prepend("<a href='#' title='+' class='ui-icon <%=ai%>'>+</a>");这实际上并没有改变原来的字符串,但它演示了如何将字符串发送到jQuery,并将它们转换为DOM元素,这些元素可以从结果的jQuery对象中操作,就像将它们添加到DOM中一样。
请注意,如果需要在字符串的顶层查找元素,则可以使用use .filter()而不是of .find()。
如果需要将结果返回到字符串中,可以添加以下内容:
d = $('<div>').append( $d ).html();虽然可能是浏览器做了一些修改,但是除了.prepend()之外,还可以对字符串进行更改。
https://stackoverflow.com/questions/4606280
复制相似问题