1
我想从html中删除dom事件属性列表?这个怎么做?如:如何使用Hpricot从html中删除事件属性?
before = "<div onclick="abc" >abc</div>"
after = clean_it(before) // after => "<div>abc</div>"
DOM_EVENT_TO_BE_REMOVE = "onclick|ondblclick|onerror|onfocus|onkeydown" // i want to remove these events
// i want to do it like this
def clean_it(html)
doc = Hpricot(html)
doc.search(DOM_EVENT_TO_BE_REMOVE).remove_attribute(DOM_EVENT_TO_BE_REMOVE)
doc.to_s
end
谢谢。
'DOM_EVENT_TO_BE_REMOVE =%(重量)[点击onfocus此onError的聚焦状态的onkeydown]'可能是有点清洁。 – kejadlen 2010-01-05 15:26:09
非常感谢。 – www 2010-01-05 16:05:20
是否需要doc.search(“* [@ onclick]”)?我认为在查找属性之前,css语法需要一个元素类型。通配符让它搜索所有元素。 – Lukas 2010-01-05 18:52:35