简体   繁体   English

HTML / JS从另一个表单元格更新一个表单元格

[英]HTML/JS Update one table cell from another table cell

Is it possible to update one table cell from another table cell? 是否可以从另一表格单元格更新一个表格单元格?

Example: I have a MediaWiki site, and on Page A I have a table cell like this: 示例:我有一个MediaWiki网站,在页面A上有一个像这样的表格单元:

<td style="background: grey; color: black;"> Proposed</td>

I want to be able to update the colour in this cell (say.. to Green) and it will update a completely different table cell on Page B (changing it to Green also). 我希望能够更新此单元格中的颜色(例如将其更改为绿色),它将更新页面B上完全不同的表格单元格(也将其更改为绿色)。

So is there a way to dynamically link two table cells, so that when one cell is changed, the other cell is also update to reflect the same change. 因此,有一种方法可以动态链接两个表单元格,以便当一个单元格更改时,另一个单元格也可以更新以反映相同的更改。

I don't think that what you're proposing is a good idea. 我认为您的建议不是一个好主意。 The color of one cell shouldn't depend on the color of some cell in a completely different table. 一个单元格的颜色不应取决于完全不同的表中某个单元格的颜色。 Instead the colors of both cells should depend on some common resource. 相反,两个单元格的颜色都应取决于某些公共资源。

That common resource could be a CSS style, using the same CSS class for both cells (as Andrew suggested in a comment). 该公共资源可以是CSS样式,两个单元格都使用相同的CSS类(如Andrew在评论中建议的那样)。

For example, you would define the CSS class proposed-cell (most likely in MediaWiki:Common.css ): 例如,您将定义CSS类MediaWiki:Common.css proposed-cell (最有可能在MediaWiki:Common.css ):

.proposed-cell 
{
    color: black;
}

And then use it like this: 然后像这样使用它:

<td class="proposed-cell">

Or it could be a MediaWiki template, that you would reference from cell style. 也可以是MediaWiki模板,您可以从单元格样式中引用它。

For example, you could create the page Template:Proposed color , whose contents will be black . 例如,您可以创建页面Template:Proposed color ,其内容将为black

Then you would use it like this: 然后,您将像这样使用它:

<td style="color: {{Proposed color}};">

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

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