Making use of document.forms[0].elements['someid'].style.backgroundColor

时间:2015-09-01 21:47:58

标签: javascript php html css

I set document.forms[0].elements['someid'].style.backgroundColor="red" in a form and submit it.

How can I get the value of "red", so that I can make use of it in another page to set the background-color of a td row? When I submit the form, my intent is to send $_POST['someid'].style.backgroundColor to the next page with the color value. How can I do this?

2 个答案:

答案 0 :(得分:1)

I'm assuming you have a td like this:

<table>
    <tbody>
        <tr>
            <td></td>
        </tr>
    </tbody>
</table>

In that case, you'd want something like this:

<table>
    <tbody>
        <tr>
            <td <?php if(!empty($_POST['someid'])) echo 'style="background-color:'.htmlentities($_POST['someid']).'"'; ?>></td>
        </tr>
    </tbody>
</table>

If you want to style every td, you'd need to add code like this:

if(!empty($_POST['someid'])){
    echo '<style>td{background-color:'.htmlentities($_POST['someid']).';}</style>';
}

答案 1 :(得分:0)

 echo "<style> ".$myobject." { background-color:".$_POST['someid']."; } </style>";