<html>
<div id="div1" style="border:1px solid" onclick="change()">
aaa
</div>
</html>
<?php
/*echo 'php输出:';
echo "<script>document.write(document.getElementById('div1').style)</script>";
echo '<hr>';*/
?>
<script>
function change()
{
document.getElementById('div1').style = "border:5px solid";
}
</script>

解决方案 »

  1.   

    要这么写对。
    <html>
    <div id="div1" style="border:1px solid" onclick="change()">
    aaa
    </div>
    </html>
    <script>
    function change()
    {
    alert('test');
    document.getElementById('div1').style.border = "5px solid";
    alert('test2');
    alert(document.getElementById('div1').style);
    alert(document.getElementById('div1').style.border);
    }
    </script>
      

  2.   

    document.getElementById('div1').style.borderWidth = "5px";
    document.getElementById('div1').style.borderStyle = "solid";
    document.getElementById('div1').style.borderColor = "red";
      

  3.   

    function change()
    {
    document.getElementById('div1').cssText= "border:5px solid red";
    }
      

  4.   

    function change()
    {
    document.getElementById('div1').style.cssText= "border:5px solid red";
    }少写了style