如何使用 jquery 获取输入按钮的值? [英] How to get value for a input button using jquery?
本文介绍了如何使用 jquery 获取输入按钮的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用 jquery 检索可点击按钮的值.我在
下有 3 个按钮:
如果我点击按钮 1,我需要获取按钮 1 的值.我不知道,这个值究竟是如何获取的.
这是我的 js:
$(document).ready(function() {$('.button1').click(function() {var text = $(this).text();$(输入").val(text);});});
我知道我写的这个脚本是错误的,因为我得到的值是一、二、三".
解决方案
像任何其他输入一样,使用 .val() 获取按钮的值:
$('input:button').click(function() {警报($(this).val());});
我不确定你到底想用你的脚本做什么!
I need to retrieve a value for a clickable button using jquery. I have 3 buttons under a <div>
:
<div class="button1">
<input type="button" value="one" id="One" onclick= "location.href='index.html'"/>
<input type="button" value="two" id="Two" onclick="location.href='index.html'" />
<input type="button" value="three" id="Three" onclick="location.href='index.html'" />
</div>
If I click on button 1, I need to get value for a button 1. I don't know, how exactly get the value of this.
Here is my js:
$(document).ready(function() {
$('.button1').click(function() {
var text = $(this).text();
$("input").val(text);
});
});
I know this script I wrote is wrong, because I am getting values as "one,two,three".
解决方案
Like any other input, to get the value of a button use .val():
$('input:button').click(function() {
alert($(this).val());
});
I'm not sure exactly what you're trying to do with your script though!
这篇关于如何使用 jquery 获取输入按钮的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文