On the get click Value button

I have a button next to

<input type='button' value='Generate' onclick='f1()' /> 

now the function f1 should show a warning window containing the value of the button. in this case "Create"

How to do it?

I tried

 alert(this); alert(this.val()); 

he does not work

+4
source share
2 answers

Try it.

 <input type='button' value='Generate' onclick='f1(this)' /> 

Now remind

 function f1(objButton){ alert(objButton.value); } 

PS: val() is actually a jQuery value implementation

+15
source

Or you do it:

 <button id='button' value='Generate' onclick='f1()'>Generate</button> 

Then this is for javascript:

 Const click = document.getElementById('button') Function f1{ Alert(`${click.Value}`) } 
0
source

Source: https://habr.com/ru/post/1482784/


All Articles