【发布时间】:2012-03-15 13:55:05
【问题描述】:
我需要使用 jquery 检索可点击按钮的值。我在<div> 下有 3 个按钮:
<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>
如果我点击按钮 1,我需要获取按钮 1 的值。我不知道,究竟如何获取 this 的值。
这是我的 js:
$(document).ready(function() {
$('.button1').click(function() {
var text = $(this).text();
$("input").val(text);
});
});
我知道我写的这个脚本是错误的,因为我得到的值是“一、二、三”。
【问题讨论】: