Javascript 使Jquery变量仅在字段隐藏时起作用
我想让Jquery变量仅在页面隐藏字段时工作 在我的示例中,我有一个由PHP生成的页面。 如果用户通过目标页面访问此页面,则侧栏上的目标选择将隐藏在此php生成的页面上。 用户访问此页面的另一种方式是单击列表链接,该链接将显示所有输入字段,以便进行选择 我希望我的location\u bar变量仅在目标输入字段隐藏时访问页面时才起作用。不是当他们通过列表链接访问它时 这是我的变量和只与该变量相关的if-else语句Javascript 使Jquery变量仅在字段隐藏时起作用,javascript,jquery,Javascript,Jquery,我想让Jquery变量仅在页面隐藏字段时工作 在我的示例中,我有一个由PHP生成的页面。 如果用户通过目标页面访问此页面,则侧栏上的目标选择将隐藏在此php生成的页面上。 用户访问此页面的另一种方式是单击列表链接,该链接将显示所有输入字段,以便进行选择 我希望我的location\u bar变量仅在目标输入字段隐藏时访问页面时才起作用。不是当他们通过列表链接访问它时 这是我的变量和只与该变量相关的if-else语句 var location_bar = $("hidden input[name=
var location_bar = $("hidden input[name='destinations[]']:hidden").val();
if(location_bar <= 0){ ...........
........
}else{
jQuery.ajax({
type: 'GET',
url: 'http://www.pgtpackages.com/api_courselist.php?page='+ nextPage +'&format=html&destinations%5B%5D='+ location_bar +'',
success: function(html) {
is_loaded = true;
nextPage++;
if(html){
jQuery("#infiscroll").append(html);
jQuery('div#loadMore').hide();
}else{
jQuery('div#loadMore').replaceWith("<center><h1 style='color:red'>End of Content !!!!!!!</h1></center>");
}
}
});
}
我跳过了所有不相关的代码。
此外,当列表链接上的I console.log location_栏中出现我没有选择的随机值时。您可以检查结果是否未定义,例如:
var location_bar = $("hidden input[name='destinations[]']:hidden").val();
if(location_bar != undefined)
{
jQuery.ajax({
type: 'GET',
url: 'http://www.pgtpackages.com/api_courselist.php?page='+ nextPage +'&format=html&destinations%5B%5D='+ location_bar +'',
success: function(html) {
is_loaded = true;
nextPage++;
if(html){
jQuery("#infiscroll").append(html);
jQuery('div#loadMore').hide();
}else{
jQuery('div#loadMore').replaceWith("<center><h1 style='color:red'>End of Content !!!!!!!</h1></center>");
}
}
});
}
你能显示你的html吗?在我看来,第一行应该是var location_bar=$input[name='destinations[]']:hidden;条件应该是iflocation\u bar.length==0{。你我的好先生是个天才……我不得不使用iflocation\u bar==undefined