【发布时间】:2009-01-28 09:55:54
【问题描述】:
一个简单的,我试图在使用 jQuery 按下按钮时检索按钮的 value 属性,这就是我所拥有的:
<script type="text/javascript">
$(document).ready(function() {
$('.my_button').click(function() {
alert($(this).val());
});
});
</script>
<button class="my_button" name="buttonName" value="buttonValue">
Button Label</button>
在 Firefox 中,我的警报显示“buttonValue”,这很好,但在 IE7 中,它显示“按钮标签”。
我应该使用什么 jQuery 来始终获取按钮的值?还是我应该使用不同的方法?
非常感谢。
回答: 我现在正在使用
<input class="my_button" type="image" src="whatever.png" value="buttonValue" />
【问题讨论】:
-
为了帮助其他人阅读本文,18 票的答案是由 @postpostmodern 撰写并由 Nowaker 编辑的 :-)
标签: jquery