質問

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