Php 替换HTML Dom对象中的表
是否可以选择具有特定bgcolor的表格并将其替换为新表格 $message是我的DOM对象,它包含一个html新闻稿,如下表所示Php 替换HTML Dom对象中的表,php,Php,是否可以选择具有特定bgcolor的表格并将其替换为新表格 $message是我的DOM对象,它包含一个html新闻稿,如下表所示 <table width="100%" bgcolor="#EEEEEE"> some rows and columns </table> 一些行和列 我想用$new_表替换这个 $new_table = '<table width="100%" bgcolor="#EEEEEE"> ne
<table width="100%" bgcolor="#EEEEEE">
some rows and columns
</table>
一些行和列
我想用$new_表替换这个
$new_table = '<table width="100%" bgcolor="#EEEEEE">
new rows and columns
</table>';
$new\u table='1
新行和新列
';
您可以向表中添加一个类,然后使用jQuery选择器清空表并添加新列:
.背景灰色{
背景色:#EEEEEE;
}
一些行和列
jQuery(文档).ready(函数(){
//使用jQuery
var new_table='新行和新列';
$('table.backGroundGray').empty().html(新表格);
});
下面是一个JSFIDLE:
是的,谢谢您的帮助,但不幸的是,这没有加载到浏览器中。该表位于名为$message的HTML DOM对象中。我可以通过
$old\u table=$DOM->getElementsByTagName('table')->项(3)删除该表$old\u table->parentNode->removeChild($old\u table)代码>但不确定如何将其替换为$new_table
<style>
.backGroundGray{
background-color: #EEEEEE;
}
</style>
<table width="100%" class="backGroundGray">
<tr>
<td>
some rows and columns
</td>
</tr>
</table>
<script>
jQuery(document).ready(function(){
//Using jQuery
var new_table = '<table width="100%" class="backGroundGray"><tr><td>new rows and columns</td></tr></table>';
$('table.backGroundGray').empty().html(new_table);
});
</script>