admin管理员组文章数量:1419248
I am very new to this, but I wrote this and thought it would work first time, but I get an 'ReferenceError: Can't find variable: street' console error.
I get this error if I click on the 'Street' button.
It's quite basic but this is the first time I've made a function to use a var/ref from the onClick attribute.
Please see onClick markup...
<a href="#" title="View Supersport" onclick="bikeFilter(supersport)">Supersport</a>
<a href="#" title="View Street" onclick="bikeFilter(street)">Street</a>
<a href="#" title="View Cruiser" onclick="bikeFilter(cruiser)">Cruiser</a>
<a href="#" title="View Scooter" onclick="bikeFilter(scooter)">Scooter</a>
<a href="#" title="Motocross" onclick="bikeFilter(motocross)">Motocross</a>
<a href="#" title="Enduro" onclick="bikeFilter(enduro)">Enduro</a>
<a href="#" title="Kids" onclick="bikeFilter(kids)">Kids</a>
then please see my function, which gets the ref error above...
Also please note I am trying to use the onClick var/ref within my function so I can target specific elements relative to the button being clicked.
bikeFilter = function (y) {
$('.bike').fadeOut();
scrollTo(186);
$('.bike[data-group=' + y + ']').fadeIn();
bikeSliderNav();
bikeSlider();
return false;
}
Any expert advice would be really helpful.
Thanks in advance.
I am very new to this, but I wrote this and thought it would work first time, but I get an 'ReferenceError: Can't find variable: street' console error.
I get this error if I click on the 'Street' button.
It's quite basic but this is the first time I've made a function to use a var/ref from the onClick attribute.
Please see onClick markup...
<a href="#" title="View Supersport" onclick="bikeFilter(supersport)">Supersport</a>
<a href="#" title="View Street" onclick="bikeFilter(street)">Street</a>
<a href="#" title="View Cruiser" onclick="bikeFilter(cruiser)">Cruiser</a>
<a href="#" title="View Scooter" onclick="bikeFilter(scooter)">Scooter</a>
<a href="#" title="Motocross" onclick="bikeFilter(motocross)">Motocross</a>
<a href="#" title="Enduro" onclick="bikeFilter(enduro)">Enduro</a>
<a href="#" title="Kids" onclick="bikeFilter(kids)">Kids</a>
then please see my function, which gets the ref error above...
Also please note I am trying to use the onClick var/ref within my function so I can target specific elements relative to the button being clicked.
bikeFilter = function (y) {
$('.bike').fadeOut();
scrollTo(186);
$('.bike[data-group=' + y + ']').fadeIn();
bikeSliderNav();
bikeSlider();
return false;
}
Any expert advice would be really helpful.
Thanks in advance.
Share Improve this question asked Nov 4, 2012 at 19:19 JoshcJoshc 3,86316 gold badges81 silver badges125 bronze badges2 Answers
Reset to default 1You'd probably wanna pass a String as input to your function and not the name of an undeclared and uninstantiated variable.
Try to use the single quotes to refer it as a String constant (you need single quotes since you are already using double quotes to tell your html tag the attribute value):
onclick="bikeFilter('scooter')"
Take a look here to see the difference in data typing in js, and here for a quick start about functions.
You should use them like :
onclick="bikeFilter('motocross')"
Don't forget to put ' around your parameters
本文标签: javascriptrun jQuery function by inline onClick and use function variablereferenceStack Overflow
版权声明:本文标题:javascript - run jQuery function by inline onClick and use function variablereference - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745278336a2651305.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论