如何将HTML按钮值作为参数传递给我的javascript?
问题描述:
我有多个按钮对应多个文本区域要清除。我需要发送函数来处理所有这些按钮并单独处理每个按钮
I have multiple buttons corresponding to multiple text areas to clear. I need to send to have a function to handle all of these buttons and handle each seperately
<html>
<head>
<script src="jquery-1.6.js"></script>
<script type="text/javascript">
function getUniqueButtonValue(value)
{
alert(value);
$("value").hide();
}
</script>
</head>
<body>
<button id=someUinqueId value=something>Clear Selection</button>
</body>
</html>
答
撇开你放置一个独特的事实值
属性中的id而不是 id
属性...这里是小提琴。
Setting aside the fact that you're placing a unique id in the value
attribute rather than the id
attribute... here's a fiddle.
$(document).ready(function(){
$("button").click(function(){
var me = $(this);
// do whatever with me
alert(me.val());
me.hide();
});
});