سؤال

I have another query, I wanted to set the attribute of my element with an event, I tried this one textbox1.setAttribute("onclick","save_data(event,this)");

but still it doesnt work. Can you help me whats the proper way to do this here is my function.

function save_data(e, x){
            if(e.keyCode == 13)
            {
                save_fnc(x);
                e.preventDefault();
            }

        }
هل كانت مفيدة؟

المحلول

Use addEventListener() for attach the hanlder to element on particular event.

textbox1.addEventListener('click', function (e){
  if(e.keyCode == 13){
      save_fnc(this);
      e.preventDefault();
   }
}) 

نصائح أخرى

For onclick you can directly use

 textbox1.onclick=function(e){
 //do required work
 }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top