尝试使用javascript原型在锚点周围添加标题

尝试使用javascript原型在锚点周围添加标题,javascript,prototypejs,Javascript,Prototypejs,我试图用Prototype在几个锚周围放置标题。但它不起作用?有人能帮我吗?谢谢 function placeheader(item, i) { item.insert({ //This doesnt work: before: "<h3>", after: "</h3>

我试图用Prototype在几个锚周围放置标题。但它不起作用?有人能帮我吗?谢谢

            function placeheader(item, i)
            {
                item.insert({
                    //This doesnt work:  
                    before: "<h3>",
                    after: "</h3>"

                    //This works:           
                    //top: "test3",
                    //bottom: "test4"
                }); 
            }               
            $$('div.subresult a').each(placeheader);
function placeheader(项目,i)
{
项目.插入({
//这不起作用:
在以下日期之前:,
“之后”
//这项工作:
//顶部:“test3”,
//底部:“test4”
}); 
}               
$$('div.subresult a')。每个(placeheader);

恐怕无法将insert()方法用于部分标记,请尝试以下操作:

function placeheader(item) {
    var header = $(document.createElement("h3"));
    item.up().insertBefore(header, item);
    item.remove();
    header.appendChild(item);
}
$$("div.subresult a").each(placeheader);
尝试
wrap()
方法

$$('div.subresult a').each(function(item){
    var header = new Element('h3');
    item.wrap(header);

});

谢谢这也很好用!:-)从不知道包裹方法