سؤال

I have a data in the object section_data.title and i am trying to use str.sup() where str=section_data.title; and str holds following data:

str="Not less than 30 net ft2 (2.8 net m2) per patient in a hospital or nursing home, or not less than 15 net ft2 (1.4 net m2) per resident in a limited care facility, shall be provided within the aggregated area of corridors, patient rooms, treatment rooms, lounge or dining areas, and other similar areas on each side of the horizontal exit. On stories not housing bed or litterborne patients, not less than 6 net ft2 (0.56 net m2) per occupant shall be provided on each side of the horizontal exit for the total number of occupants in adjoining compartments."

Now I want to add superscript for the bold words indicated above (e.g ft2). How can I do this using str.sup() or are there any other alternative method to do so in javascript? Or any other tricks?

هل كانت مفيدة؟

المحلول

String in javascript is not formatted. You can only do that when you output to HTML. So basically you must write it like this

var str = "Not less than 30 net ft<sup>2</sup> (2.8 net m<sup>2</sup>)";
document.write(str);

You can do a find and replace for all string contain ft2 and m2 turn them into ft<sup>2</sup> and m<sup>2</sup>

str.replace(/ft2/g,"ft<sup>2</sup>");  //But it not safe...
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top