onclick属性怎么传递参数
1个回答
2015-09-03
展开全部
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="js/jquery/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".title").click(function(){
var id=$(this).data("id");
var name=$(this).data("name");
alert("Id: "+id+" ; Name: "+name);});
});
function onClick(e){
var id=e.getAttribute("data-id");
var name=e.getAttribute("data-name");
alert("Id: "+id+" ; Name: "+name);
}
</script>
</head>
<body>
<div class="title" data-id="1" data-name="Microsoft">Click Me</div>
<div id="add" data-id="2" data-name="Google" onclick="onClick(this)">Click Me</div>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="js/jquery/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".title").click(function(){
var id=$(this).data("id");
var name=$(this).data("name");
alert("Id: "+id+" ; Name: "+name);});
});
function onClick(e){
var id=e.getAttribute("data-id");
var name=e.getAttribute("data-name");
alert("Id: "+id+" ; Name: "+name);
}
</script>
</head>
<body>
<div class="title" data-id="1" data-name="Microsoft">Click Me</div>
<div id="add" data-id="2" data-name="Google" onclick="onClick(this)">Click Me</div>
</body>
</html>
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询