简体   繁体   English

将表格或td标签的内容设为粗体

[英]Make contents of a table or td tag bold

I'm working with some legacy code and encountered the following issue. 我正在使用一些旧代码,遇到了以下问题。

I'm using YAHOO.widget.DataTable( elContainer, aColumnDefs, oDataSource, oConfigs ) structure to modify html elements in a table. 我正在使用YAHOO.widget.DataTable(elContainer,aColumnDefs,oDataSource,oConfigs)结构来修改表中的html元素。

I am running a basic number to US currency conversion on the code in one td of this table. 我正在此表的1 td中的代码上运行基本数字到美元的转换。 It works for other tables however it fails in this table because all elements are set to bold via the "< \\b >" tag which is being pulled into the Yahoo Table structure as the td value. 它适用于其他表,但是在此表中失败,因为所有元素都通过“ <\\ b>”标记设置为粗体,该标记被作为td值拉入Yahoo Table结构。

Ex: 例如:

<td>
    <b><s:property value="totalTransactions"/> my text </b>
</td>

For example when the table queries the value at this td it gets "<b><s:property value="totalTransactions"/> my text</b>". 例如,当表查询此td处的值时,它将得到"<b><s:property value="totalTransactions"/> my text</b>". When really all I want is my text . 我真正想要的只是我的文字

My preffered solution is to remove the b tags. 我最好的解决方法是删除b标签。

So the code can run (and doesn't need to differ between different tables and it doesn't need to clean them all first and then attempt to distinguish when it should add bold tags back) 因此,代码可以运行(并且不需要在不同的表之间进行区分,也不需要先清除它们,然后尝试区分何时应该添加粗体标签)。

For example I could check if html exists remove it, modify the number, and then add the html back. 例如,我可以检查html是否存在,将其删除,修改数字,然后再添加html。 I think it's cleaner (personal preference perhaps) to modify the table so that it keeps the bold font for all elements in it without adding text inside the td tag. 我认为修改表比较干净(也许是个人喜好),以便它在表中保留所有元素的粗体而不在td标签内添加文本。

I looked at: Bold a single line in html table <td> 我看着: 在html表<td>中加粗一行

I tried 我试过了

<td style="font-weight:bold"> my text </td>

However it does not become bold. 但是,它不会变大胆。

the bold tag makes the text bold when done like this: 像这样完成时,bold标签使文本变为粗体:

<td>
    <b>my text</b>
</td>

However the b tag interferes with my function. 但是,b标签会干扰我的功能。 My thought that is due to the yahoo injection: 我的想法是由于雅虎注入:

result =  "$"+myAmount;
el.innerHTML = result;  

That the bold style might be overwritten. 粗体可能会被覆盖。 Are there any solutions? 有什么解决办法吗? Or is there another reason style doesn't work? 还是有其他原因导致样式无效?

I believe the issue is due to the fact that I'm using a struct: see http://www.mkyong.com/struts2/struts-2-property-tag-example/ . 我认为问题是由于我使用了一个结构:请参阅http://www.mkyong.com/struts2/struts-2-property-tag-example/

I am unsure of why traditional styling rules do not apply. 我不确定为什么传统的样式规则不适用。 Or perhaps I have made an error? 还是我犯了一个错误? The page renders fine just without any bold. 页面呈现良好,只是没有任何粗体。 I see no logged errors. 我没有看到记录的错误。

From what I understood form your question there are 2 possible solutions with inline css. 据我所知,从您的问题来看,内联css有2种可能的解决方案。

First one 第一

<html>
<head>
<style>
    table td {
        font-weight:bold;
    }
</style>
</head>
<body>
<table><tr><td>Text inside table cell</td></tr></table>
</body>
</html>

Second one 第二个

<table>
    <tr><td style="font-weight:bold">Text inside the table</td></tr>
</table>

one with css declaration: 一个带有CSS声明的代码:

table td {
            font-weight:bold;
        }

Another solution will be using strong tag to wrap the text. 另一个解决方案是使用强标签来包装文本。

<table><tr><td><strong>Text goes here</strong></td></tr></table>

I hope I understood the question correctly and your goal is to bold all text in one table. 我希望我正确理解了这个问题,您的目标是将所有文本加粗在一个表中。 This inline style makes all texts in the cells from the table bold: 这种内联样式使表格中单元格中的所有文本均变为粗体:

<table style="font-weight: 700;">...

or a more readable version: 或更易读的版本:

<table style="font-weight: bold;">...

While the other two answer at the moment have covered the basics, using either strong tag or using a css style (inline or in a style dec). 尽管目前其他两个答案都涵盖了基础知识,但可以使用强标签或css样式(内联或样式dec)。

If the above two still fail, perhaps another means would be using javascript or jquery to enumerate over the table and apply a bold style afterwards either directly to each td cell or table by applying a css or inserting your own b/strong tags. 如果以上两个仍然失败,则可能另一种方法是使用javascript或jquery枚举表,然后通过应用css或插入自己的b / strong标记将粗体样式直接应用于每个td单元格或表。

This may not be an option in your case, but being others will see this. 在您的情况下,这可能不是一个选择,但作为其他人,您会看到这一点。 There are still times when this is called for. 仍然有很多时候需要这样做。

I wont post any code as the basics are covered, unless you need a Javascript/jQuery code. 我不会发布任何代码,因为涵盖了基础知识,除非您需要Javascript / jQuery代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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