找到img id和src并添加到数组中

时间:2012-05-23 22:48:52

标签: javascript

继承我的HTML代码:

<div id="cmdt_1_29d" class="dt_state2" onclick="sel_test(this.id)">
    <img id="cmdt_1_29i" onclick="dropit('cmdt_1_29');"
         src="http://hitechpackaging.zes.zeald.com/interchange-5/en_US/ico_minus.png">
    <span class="dt_link">
        <a href="javascript://">CARTON &amp; BOARD</a>
    </span> 
</div> 
<div id="cmdt_2_31d" class="dt_istate1" onclick="sel_test(this.id)">
    <img src="/site/hitechpackaging/images/items/test.jpb ">
    <a href="https://secure.zeald.com/hitechpackaging/shop/CARTON%20%20%20%20BOARD/CORRUGATED%20%20CORNER%20BOARD?mv_pc=21497">CORRUGATED &amp; CORNER BOARD</a>
</div>

dropit函数修改了我不想要的img src,遗憾的是我无法修改, 我可以以某种方式在修改数据之前将数据读入数组,并且我可以将数据添加回图像。

1 个答案:

答案 0 :(得分:0)

删除点击处理程序:

var i = document.getElementById('cmd1_1_29i');
i.onclick = null;

或者,如果您仍想调用原始点击处理程序:

var i = document.getElementById('cmd1_1_29i');
_onclick = i.onclick;

i.onclick = function(e) {
    // do what you want here
    _onclick && _onclick.apply(this, [e]);
}
​