我需要使用jquery检索可点击按钮的值.我有3个按钮<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>
Run Code Online (Sandbox Code Playgroud)
如果我点击按钮1我需要获得按钮1的值.我不知道如何获得这个值.
这是我的js.
$(document).ready(function() {
$('.button1').click(function() {
var text = $(this).text();
$("input").val(text);
});
});
Run Code Online (Sandbox Code Playgroud)
我知道这个js脚本我写错了.因为我的价值观是"一,二,三".
提前致谢.
Ric*_*ton 24
像任何其他输入一样,要获取按钮的值,请使用.val():
$('input:button').click(function() {
alert($(this).val());
});?
Run Code Online (Sandbox Code Playgroud)
我不确定你的脚本究竟是怎么做的!