简体   繁体   中英

variables accesable in anonymous javascript function

I have a problem to access temp in the anonymous function. the toggle works just fine. This is the workaround because I was not able to set callback functions to the .toggle()

I would wish to .toggle("drop", 200, function(){}); and in the function I call the second toggle to show the element when the text changed. I wasn't getting this working so I tried the setTimeout workaround but this won't work as well. Please tell me how can I access temp in it or how can I use the callback of .toggle() ?

for (var i = 0; i < array.length; i++) {
  var temp = array[i].split("&");

  setTimeout(function(){
    $('td[vvalue="'+temp[0] + '"] > a').text("A");
  }, 300);

  $('td[vvalue="'+temp[0] + '"]').toggle("drop", 200);
  $('td[vvalue="'+temp[0] + '"]').toggle("drop", 200);
}

I think it could be an issue with your selector rather than the temp value in the function:

$('td[vvalue="'+temp[0] + '"] > a').text("A");

should probably be:

$('td[value="'+temp[0] + '"] > a').text("A");

Notice the spelling error on "value". td elements do not have a value attribute. You may want to rethink your markup. If you need a custom attribute, html5 has the new data- attributes for custom attributes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM