Removing onchange event vis the dom

2019-07-23 18:34发布

问题:

I have the following html

<td valign="top" nowrap="nowrap" align="left" rowspan="4">
<div id="win0divCLASS_SRCH_WRK2_SUBJECT$69$">
<input type="text"
    onchange="addchg_win0(this);oChange_win0=this;"
    maxlength="8"
    style="width:60px; "
    class="PSEDITBOX"
    value=""
    tabindex="31"
    id="CLASS_SRCH_WRK2_SUBJECT$69$"
    name="CLASS_SRCH_WRK2_SUBJECT$69$" />
</div></td>

I'm trying to figure out how to either delete the onchange from the element, or to set it to null..

Articles I've seen indicate that using the removeEventlistener should work. I've tried::

document.getElementById(\"CLASS_SRCH_WRK2_SUBJECT$69$\").removeEventListener('onchange',addchg_win0(this);oChange_win0=this;, false)

as well as

document.getElementById(\"CLASS_SRCH_WRK2_SUBJECT$69$\").onchange=null;

with no luck.

Any pointers/thoughts on this??

回答1:

give a try to document.getElementById("CLASS_SRCH_WRK2_SUBJECT$69$").removeAttribute("onchange");



回答2:

try

document.getElementById("CLASS_SRCH_WRK2_SUBJECT$69$").onchange="";