简体   繁体   中英

Right align text in a javascript

I am a beginner in javascript. I have researched the forum for answers to my question. there were a couple that I think I could have used except with my code I am, not sure where or how to put it. Can someone help me? I need to show the eight rows right aligned. Thank you !!!

results.each(function(index) {
var result = "";
var theseClmStats = record.tables.PlanClmStats[index].tables.ClmStats;
var thisPlanClmStats = record.tables.PlanClmStats[index];
//query("#test").append(thisPlanClmStats.fields["PlanName"]+ " (" + index + ') has ' + thisPlanClmStats.tables.length +' table(s)<br/>');
if(thisPlanClmStats.fields.PlanId != null) {
    theseClaimSource = thisPlanClmStats.tables.ClmStats.ClaimSource;
    result += '<tr data-repeat="" data-breakable="ClaimSource' + index +'">';
    result += '</tr>';

    var ClmStatslen = theseClmStats.length;

    for (var i=0; i < ClmStatslen; i++) {
        var thisClmStats = theseClmStats[i];

        result += '<tr data-repeat="" data-breakable="ClmStats' + i +'">';
        result += '<td><br/></td>';
        result += '<td class="data PlanID" textAlign:right>'+ thisClmStats.fields["ClaimSource"] + '</td>';
        result += '<td class="data PlanID">'+ thisClmStats.fields["UniqueParticipants4"] + '</td>';
        result += '<td class="data PlanID">'+ thisClmStats.fields["ClaimVolume4"] + '</td>';
        result += '<td class="data PlanID">'+ thisClmStats.fields["ClaimAverage4"] + '</td>';
        result += '<td class="data PlanID">'+ thisClmStats.fields["PercentageofTOTALVolume4"] + '</td>';
        result += '<td class="data PlanID">'+ thisClmStats.fields["Paid4"] + '</td>';
        result += '<td class="data PlanID">'+ thisClmStats.fields["Pending4"] + '</td>';
        result += '<td class="data PlanID">'+ thisClmStats.fields["Denied4"] + '</td>';

        result += '</tr>';
    }
}

this.after(result);

});

You seem to be mixing a bunch of concepts together. To make the text right-align in a table cell ( <td> ), you could just apply CSS to one of the classes you are using, such as:

<style type="text/css">
     td.PlanID {text-align:right}
</style>

Then, when you append the HTML, the CSS will automatically be applied.

If you can't adjust the CSS file (or HTML file), then try adding to your JS:

document.getElementsByClassName("PlanID").style.textAlign= "right";

You would then add this line at the end of your Javascript. But it probably is better (and cleaner) to use the CSS method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM