comma separating the texts of link buttons
i am storing the names of a series of link buttons having common class in an array and printing the value of array in a span but as all linkbuttons have common classes so they are getting stored as a single entry in the array and while printing the value it is not getting comma separated
the markup that is the aspx part is some what like this
<div class="rightSortControl">
<asp:Label ID="lblFilterLabel" runat="server"
CssClass="sortLabel" Text="View:">
</asp:Label>
<asp:LinkButton ID="lbtnToBePublished" runat="server"
Text="To Be Published" CssClass="filterButton" Visible="false"
OnCommand="doSomething"/>
<asp:LinkButton ID="lbtnBookmarkedByMe" runat="server"
Text="Bookmarked" CssClass="filterButton" Visible="false"
OnCommand="doSomething"/>
<asp:LinkButton ID="lbtnAuthoredByMeFilter" runat="server"
Text="Authore开发者_JS百科d by Me" CssClass="filterButton"
OnCommand="doSomething"/>
<asp:LinkButton ID="lbtnTakenByMe" runat="server"
Text="Taken by Me" CssClass="filterButton" Visible="false"
OnCommand="doSomething"/>
<asp:LinkButton ID="lbtnTakingInProgress" runat="server"
Text="Taking" CssClass="filterButton" Visible="false"
OnCommand="doSomething"/>
</div>
here the class mentioned is 'filterbutton' which i am changing dynamically whenever the user click on those linkbuttons to 'selectedButton'.
$('.rightSortControl').each(function()
{
if ($(this).find('.selectedButton').length > 0)
{
arrAppliedFilter.push($.trim($(this).find('.selectedButton').text()));
}
});
alert(arrAppliedFilter); //not comma separating the names what to do
what i have to do to fix this
Use the Array join method:
alert(arrAppliedFilter.join(','));
alert(arrAppliedFilter.join(','));
Well i got the answer i was doing a mistake over there
$('.rightSortControl').find('a.selectedButton').each(function()
{
arrAppliedFilter.push($.trim($(this).text()));
});
and it is working fine any ways thanks everybody for your support
var message = [ 'foo', 'bar' ];
message.join(',');
console.log(message);
Using alert()
to dump a value can often mislead. The result depends on the browser's specific implementation of alert()
. For example, in Google Chrome v10.0.648.45 dev, alert(message)
results in a message box containing foo,bar
. Note the comma. Though it is not present in the message
variable, the box displays it. Hence for more reliability when looking into (dumping) data structures, use console.log()
(if your browser supports it).
精彩评论