2014-09-30 66 views
0

这是我的jsfiddle当一个变量中有空间,股利是不可折叠

http://jsfiddle.net/nvx4tkLt/8/

我noticied,如果变量,它出现了空间,股利是不可折叠。

例如在jsfiddle中,如果您点击兄弟首页div不可折叠。

当在DIV clciked这是正在执行

$(document).on('click', '.lielement', function() { 
    var locationname = $(this).attr("id"); 
    if($(this).find('.restListings').length) 
    $(this).find('.restListings').remove() 
    else 
    displayingRestaurantsForLabel(locationname); 
}); 
function displayingRestaurantsForLabel(locationname) 
{ 
    showRestaurantDetailsByLocation(restaurantsbylocation,locationname); 
} 
function showRestaurantDetailsByLocation(response, locationname) { 
    var responsedata = JSON.stringify(response); 
    $("#restmenu").find('.restListings').remove(); 
    var ulhtml = $('<ul class="restListings"></ul>'); 
    var divhtml = $('<div class="inner-intit"><sub class="sub">Yours Favorite Restaurant</sub></div>'); 
    divhtml.append('<br>'); 
    for (var i = 0; i < response.length; i++) { 
     divhtml.append('<li class="grayOut-Rest innerChild"><h6> '+response[i].vendor_name+'</h6></li>'); 
     existingrestaurants.push(response[i].vendor_id); 
    } 
    ulhtml.append(divhtml); 
    $("#restmenu").find('#'+locationname.trim()).append(ulhtml); 
} 

有谁请让我知道什么是问题的代码?

在此先感谢。

回答

1

问题是,您使用的名称为id。所以ID有一个空格,这是无效的。

id属性值必须以罗马字母(a-z或A-Z)中的一个字母开头;这可以跟随字母(a-z或A-Z),数字(0-9),连字符( - ),下划线(_),冒号(:)和句点(。)的任意组合。

http://www.sitepoint.com/web-foundations/id-html-attribute/

所以,你应该改变你的ID。您可以像现在一样使用该名称,但应先删除所有空格。

+0

非常感谢你对这个问题的解释。 – Pawan 2014-09-30 07:11:31

相关问题