How to connect var javascript with text ?
var xxx = 5;
$('html, body').animate({ scrollTop: ($("validate_focus"+xxx).offset().top - page_height_val/2)}, 'slow');
on code i want to connect var xxx
with text validate_focus
to validate_focus5
But not work , How can i do that ?
That's the correct way to do but you're missing the selector:
var xxx = 5;
$('html, body').animate({
scrollTop:
($(".validate_focus"+xxx)
// ^^^ use . if it is class, use # if it is id
.offset().top - page_height_val/2)
}, 'slow');
You need something like ...
$("#validate_focus"+xxx)
... if validate_focus5
is a Id, or ...
$(".validate_focus"+xxx)
... if validate_focus5
is a Class.
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.