jQuery 更改 img 和文件夹 src
我在单击某个按钮时更改图像的目标文件夹,以及在将鼠标悬停在另一个元素上时更改该图像的 src,同时保留新选择的文件夹时遇到问题。
我的代码在这里,jquery 摘录如下:
<script type="text/javascript">
$(document).ready(function(){
imgFldr = 'period-black';
//click the hardware buttons and change the folder where the images are coming from, but not the image itself (by name)
$('#standardBlack').click(function(){
$("#pic").attr("src",'standard-black/'+$("#pic").attr("src").split('/')[1]);
});
$('#standardGold').click(function(){
$("#pic").attr("src",'standard-gold/'+$("#pic").attr("src").split('/')[1]);
});
$('#standardChrome').click(function(){
$("#pic").attr("src",'standard-chrome/'+$("#pic").attr("src").split('/')[1]);
});
//on hovering the 21 or 24 colour options, change the colour of the image but not the folder
$('#black').hover(function(){
$("#pic").attr("src",imgFldr+"/black.jpg");
});
$('#blueGrey').hover(function(){
$("#pic").attr("src",imgFldr+"/blue-grey.jpg");
});
$('#burgundy').hover(function(){
$("#pic").attr("src",imgFldr+"/burgundy.jpg");
});
});
</script>
发生的情况是,一旦您将鼠标悬停在 src 更改按钮上,文件夹就会返回到原始变量,但它应该保留所选文件夹。
关于如何正常工作有什么想法吗?
I'm having problems with changing the destination folder of my images when clicking a certain button, and changing the src of this image when hovering over another element, whilst retaining the new chosen folder.
The code I have is here, with the jquery excerpt here:
<script type="text/javascript">
$(document).ready(function(){
imgFldr = 'period-black';
//click the hardware buttons and change the folder where the images are coming from, but not the image itself (by name)
$('#standardBlack').click(function(){
$("#pic").attr("src",'standard-black/'+$("#pic").attr("src").split('/')[1]);
});
$('#standardGold').click(function(){
$("#pic").attr("src",'standard-gold/'+$("#pic").attr("src").split('/')[1]);
});
$('#standardChrome').click(function(){
$("#pic").attr("src",'standard-chrome/'+$("#pic").attr("src").split('/')[1]);
});
//on hovering the 21 or 24 colour options, change the colour of the image but not the folder
$('#black').hover(function(){
$("#pic").attr("src",imgFldr+"/black.jpg");
});
$('#blueGrey').hover(function(){
$("#pic").attr("src",imgFldr+"/blue-grey.jpg");
});
$('#burgundy').hover(function(){
$("#pic").attr("src",imgFldr+"/burgundy.jpg");
});
});
</script>
Whats happening is that once you hover over the src change button, the folder goes back to the original variable, but it should keep the chosen folder.
Any ideas on how this could work properly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解了脚本的作用:
等等。
If I understood correctly what the script does:
and so on.