我无法在选择项目时更新网址。这是我的代码:
jQuery("#switcher-select li a").click(function() {
jQuery("#preview").attr("src", jQuery(this).attr("href"));
jQuery("#purchase a").attr("href", jQuery(this).attr("data-demo"));
jQuery("#purchase a").html('<span class="label">Get it now</span>');
jQuery("#switcher-button").click();
jQuery("#switcher-info").html(jQuery(this).find("h2").text() + '<span id="switcher-button"><i class="button-up"></i></span>');
jQuery("#switcher-select li a").attr("data-selected", false);
var selected = jQuery(this).attr("data-selected", true);
window.location.href = "?theme=" + selected + "";
jQuery("#switcher-select li a").each(function() {
if (jQuery(this).attr("data-selected") != "true") {
jQuery(this).stop().animate({
backgroundColor: "#000"
}, 400);
}
});
return false;
});
<ul id="switcher-select">
<?php foreach( $theme_array as $theme) : ?>
<li id="<?php echo $theme["id"] ?>">
<a href="<?php echo $theme["demo_url"] ?>" data-demo="<?php echo $theme["theme_url"] ?>" data-selected="<?php if (ucfirst($theme["id"]) == $selected_theme) : echo "true"; else: echo "false"; endif; ?>">
<div class="switcher-theme-info">
<h2><?php echo ucfirst($theme["name"]) ?></h2>
<p><?php echo $theme["info"] ?></p>
</div>
</a>
<ul id="first-theme" class="demo-preview">
<li><img style="border-radius: 0 0 10px 0;" src="<?php echo $theme["screenshot"] ?>"/></li>
</ul>
</li>
<?php endforeach; ?>
</ul>
当#switcher-select li
为真时,我想要的是data-selected
ID。