get value for a input button using jquery

前提是你 提交于 2019-12-04 23:11:12

Like any other input, to get the value of a button use .val():

$('input:button').click(function() {
    alert($(this).val());
});​

http://jsfiddle.net/3QDM5/

I'm not sure exactly what you're trying to do with your script though!

use attr http://api.jquery.com/attr/

$(document).ready(function() { 
    $('#button1').click(function() { 
        var text = $(this).attr('value'); 
        $("#input").val(text); 
    }); 
}); 

example :

<input type="button" value="one" id="One" onclick= "click(this.value)'"/>

where click(this.value) is function on javascript

function click(x)
{
    //x is value from onclick button
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!