有时我会遇到变量中包含HTML元素ID的情况
例如var activePage = frontPage
。我如何使用它来获取带有jQuery的DIV元素?
因为这不起作用:var div = $('#'+activePage+'footer li a')
。
我知道我可以使用document.getElementById(activePage)
- 但我不知道如何将它与jQuery一起使用。
答案 0 :(得分:1)
你需要一个空间。 var div = $('#'+activePage+' footer li a')
。如果没有空格,jQuery将查找frontPagefooter