Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
281 views
in Technique[技术] by (71.8m points)

javascript - On click get button Value

I have a button like following

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

now the f1 function should show a alert box contain button value. in this case 'Generate'

How to do this?

I tried

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

it does not work

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this.

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

Now alert like

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

P.S: val() is actually a jQuery implementation of value


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...