onclick event input button does not fire on IE 11

2019-09-08 16:41发布

I have input elements of type button created using jquery function. These buttons are added dynamically via script that fire on image load. The info on the buttons is read from metadata that is available as a object on the DOM.

When I click on these elements, these do not fire (or not action happens) on IE11. It works fine on FF27.

DOM explorer (example below) shows the onclick attribute is set fine for these elements (since it working on FF).

jquery used to build the input buttons (done in a loop, fired on image onload)

$(input).attr({
    'type': 'button',
    'id': mytds.id,
    'value': mytds.text,
    'class': 'sbarButton',
    'cmd': mytds.cmd,
    'option': mytds.option,
    'form': mytds.form,
    'args': mytds.args,
    'arg2': mytds.arg2,
    'qual': mytds.qual,
    'scope': mytds.scope,
    'IX': mytds.IX,
    'IY': mytds.IY,
    'IZ': mytds.IZ,
    'forward': mytds.forward,
    'onclick':'clicked()'
});

function clicked() { alert ("Clicked:"); }

I have tried to reassign the click attribute using other options to see if it will work on IE, for e.g.

$(input)[0].setAttribute('onclick','clicked()');

It doesn't throw any script error, pretty much does nothing on click on these buttons.

Help is appreciated to find out what's going on & correct the situation.

Thanks in advance.

0条回答
登录 后发表回答