【发布时间】:2012-10-29 23:47:56
【问题描述】:
这应该很简单,但我在这个问题上疯了。基本上我想要做的是在页面上显示之前从返回的 HTML 数据中替换一些标签。例如:
$.ajax({
url: url,
cache: false,
type: 'GET',
success: function(data) {
// Here i need to replace href in ALL <a> tags and add the onclick attrib with the contents from the href
$('#floaty-dialog').html(modifieddata);
}
});
如何预处理 HTML 数据并将所有 href 属性替换为 # 并将 onclick 属性添加到相同的链接??
【问题讨论】:
-
像修改其他 dom 元素一样修改它。
var modifieddata = $(data); modifieddata.find('a').each(function(){...})
标签: jquery html ajax parsing replace