2014-09-30 67 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