【发布时间】:2012-08-18 01:51:31
【问题描述】:
我不太擅长编写 jQuery,但请原谅这个幼稚的问题:
我希望将单击的 href 值放入“backstretch”jQ 插件中。 (http://srobbin.com/jquery-plugins/jquery-backstretch/)
我的代码如下所示:
$(function() {
var bgImage = $('.active').attr("href"); //gets the value of the href on the a with the class 'active' and puts it in a variable.
$('.clicks a').click(function() {
$('.clicks a').removeClass('active');
$(this).addClass('active');
return false;
}) //removes all 'active' classes, and puts the 'active' class on the clicked a tag.
$.backstretch("bgImage", {speed: 150}); // uses the value the variable in this plugin.
}); //end.ready
但它不起作用,有什么想法吗?提前致谢!
【问题讨论】:
-
至少你写的是
$(function() {而不是jQuery(document).ready(function() {。天哪,当我看到它时,我讨厌。
标签: jquery variables jquery-plugins