Javascript 如何在html中使用jquery变量
我正在使用jquery,我想在这里做的是能够根据悬停到的链接设置将显示的图像Javascript 如何在html中使用jquery变量,javascript,jquery,html,image,Javascript,Jquery,Html,Image,我正在使用jquery,我想在这里做的是能够根据悬停到的链接设置将显示的图像 <script type='text/javascript'> $(function(){ $('img').hide(); $('a').mouseenter(function(){ var currentimg= $(this).html(); alert(currentimg); $("img[src=currentimg.jpg]").show(); //I want
<script type='text/javascript'>
$(function(){
$('img').hide();
$('a').mouseenter(function(){
var currentimg= $(this).html();
alert(currentimg);
$("img[src=currentimg.jpg]").show(); //I want to use currentimg variable here for the name of the jpg file
});
$('a').mouseleave(function(){
$('img').hide();
});
});
</script>
您只需连接字符串即可使用,例如:
$("img[src='" + currentimg +"']").show();
请注意,.mouseenterhandler.mouseleavehandler还有一个快捷方式,如下所示:
$(function(){
$('img').hide();
$('a').hover(function(){
var currentimg = $(this).html();
$("img[src='" + currentimg +"']").show();
}, function(){
$('img').hide();
});
});
您只需连接字符串即可使用,例如:
$("img[src='" + currentimg +"']").show();
请注意,.mouseenterhandler.mouseleavehandler还有一个快捷方式,如下所示:
$(function(){
$('img').hide();
$('a').hover(function(){
var currentimg = $(this).html();
$("img[src='" + currentimg +"']").show();
}, function(){
$('img').hide();
});
});