开发者

jquery: Alert val

开发者 https://www.devze.com 2023-02-16 09:32 出处:网络
This is a quick one... Why doesn\'t it work? var currentSlideshow = $(\".slideshow div\").index(); $(\'#开发者_如何学Cmenu ul li a\').click(function() {

This is a quick one...

Why doesn't it work?

var currentSlideshow = $(".slideshow div").index();     
$('#开发者_如何学Cmenu ul li a').click(function() {
    alert("currentSlideshow");


});

It won't alert anything.


you are alerting a string "currentSlideshow" instead of a variable currentSlideshow


Your selector is not selecting anything.

#menu ul li a
  1. Do you have something with id of menu?
  2. Do you have a <ul> as a child the element with id of menu?
  3. Are there <li> elements within the <ul>?
  4. Do the <li> elements have <a> elements?


I rebuild your example: look here there the event fires.

EDIT: pasted the code from jsfiddle

HTML:

<div id="menu">
<ul>

    <li><a href="">Test</a></li>
</ul>
</div>

<div class="slideshow" id="4"><div id="5"></div></div>

JS

var currentSlideshow = $(".slideshow div").index();     
$('#menu ul li a').click(function() {
   alert("currentSlideshow");
});


I would guess that selector never matches an element so the click event is never fired.

Can you post the HTML so we can see if there is a problem there?


As others have suggested please check that the selector is correct. This can be done using firebug, for example.. Try this, add a breakpoint in the handler function, check if it breaks on it.. also, if it is only for the purpose of debugging, use firebug console.

0

精彩评论

暂无评论...
验证码 换一张
取 消