如何使用jquery触发参数值的事件
我想在用户鼠标悬停时显示一个参数值。我想用jquery来实现它。我的函数返回一个未定义的值如何使用jquery触发参数值的事件,jquery,Jquery,我想在用户鼠标悬停时显示一个参数值。我想用jquery来实现它。我的函数返回一个未定义的值 <script type="text/javascript"> $(function showinfo(id, a,b){ $('div').mouseover(function(){ var html= '<div>'+ a +'</div> <div>'+b+'</div>'; $('body').ap
<script type="text/javascript">
$(function showinfo(id, a,b){
$('div').mouseover(function(){
var html= '<div>'+ a +'</div> <div>'+b+'</div>';
$('body').append(html)
})
})
</script>
$(函数showinfo(id、a、b){
$('div').mouseover(函数(){
var html=''+a+''+b+'';
$('body').append(html)
})
})
HTML:
显示信息
您有一些语法错误:
<script type="text/javascript">
$(document).ready(function(){
function showinfo(id, a,b){
var html= '<div>'+ a +'</div> <div>'+b+'</div>';
$('body').append(html);
}
});
</script>
$(文档).ready(函数(){
函数showinfo(id、a、b){
var html=''+a+''+b+'';
$('body').append(html);
}
});
功能显示信息(id、a、b){
var html=''+a+''+b+'';
$(正文).append(html);
}
然后:
显示信息
将是一个更干净的版本。但不清楚为什么要将悬停的实际div传递到函数中。您想用它做什么?我建议您稍微改变一下:
<div id="container">
<div id="showInfo" >show info</div>
</div>
显示信息
和jQuery:
$(document).ready(function() {
$("#showInfo").mouseover(function() {
showInfo($(this).attr("id"), '50', '60');
});
});
function showInfo(id, a, b) {
var html = '<div>'+a+'</div><div>'+b+'</div>';
$("#container").append(html);
}
$(文档).ready(函数(){
$(“#showInfo”).mouseover(函数(){
showInfo($(this.attr(“id”),'50','60');
});
});
函数showInfo(id、a、b){
var html=''+a+''+b+'';
$(“#容器”).append(html);
}
您还可以查看jQuery的悬停函数。
请点击此处:
<div onmouseover="showinfo(this, '50','60')">show info</div>
<div id="container">
<div id="showInfo" >show info</div>
</div>
$(document).ready(function() {
$("#showInfo").mouseover(function() {
showInfo($(this).attr("id"), '50', '60');
});
});
function showInfo(id, a, b) {
var html = '<div>'+a+'</div><div>'+b+'</div>';
$("#container").append(html);
}