我试图从html代码中给出的同名但不同的值中取出一个按钮的值。如何使用jQuery获取我们点击的按钮的值?
<html>
<input type="button" name="btn1" value="Button1" text="Button1">
<input type="button" name="btn1" value="Button2" text="Button2">
<input type="button" name="btn1" value="Button3" text="Button3">
</html>
&#13;
答案 0 :(得分:0)
您可以从attribute
获取input button
类型文字并显示。
$("input").click(function(){
var value=$(this).attr("text");
console.log(value);
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<input type="button" name="btn1" value="Button1" text="Button1">
<input type="button" name="btn1" value="Button2" text="Button2">
<input type="button" name="btn1" value="Button3" text="Button3">
</html>
&#13;