我有两个按钮...
<a data-role="button" data-theme="g" href="#tops" class="track" data-track="tops"> Tops </a>
<a data-role="button" data-theme="g" href="#dresses" class="track" data-track="dresses"> Dresses</a>
当加载href时,例如#dresses有一个图像:
<img class="item" src="images/dresses/item1.jpg")
我正在尝试设置一个 JQuery 函数,该函数将获取数据跟踪值并将其分配给一个名为 trackSelection 的变量,这样我就可以拥有:
var locationString = "images/" + trackSelection + "/item1.jpg";
$('.item').attr('src', locationString)
This way the right image will be loaded when the button is selected. 我已经尝试过了,但它没有用:
$(".track").click(function() {
var trackSelection = $(this).data("track");
});