2011-12-20 39 views
0

此處我試圖在Google地圖標記上顯示一些信息。描述包含一個長度爲500字符左右的字符串,我將其縮短爲225個字符,然後使用錨點標籤添加一個鏈接,指出顯示更多。 現在的問題, 我希望它擴大標記和顯示其餘的信息。我怎樣才能做到這一點?修整後的字符串展開並顯示完整數據

function stringTrimmer(text, flag) { 
var textLength = text.length; 
if (flag !== null && flag !== true) { 

    if (text.length > 225) { 
     var text1 = text.substring(0, 224) + "..." + "<a href=#>Show More </a>"; 
     return text1; 
    } 
} else if (flag === true) { 
    return text; 
}}; 

哪一個不工作。有人可以幫忙嗎?謝謝!

回答

0

試試這個簡單的代碼,並進行修改,以滿足您的需求

function stringTrimmer(text, flag) { 
var textLength = text.length; 
if (flag !== null && flag !== true) { 

    if (text.length > 225) { 
     var text1 = text.substring(0, 224) + "..." + "<a class='show-more' old_val='"+text+"' href=#>Show More </a>"; 
     return text1; 
    } 
} else if (flag === true) { 
    return text; 
}}; 

$('.show-more').bind('click'){ 
$('some-element').html($(this).attr('old_val')) 
}