如题,现在我想做一个html编辑器,当我选中一段文字或者一张图片时,要设置其style属性,如果实现?比如:
<img style="border:solid 1px red" src="img/img001.jpg" />设置其中的style值。

解决方案 »

  1.   

    首先获得该对象  然后设置该对象的style集合中的相应属性就行了 
      

  2.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta NAME="Generator" CONTENT="EditPlus">
    <meta NAME="Author" CONTENT="">
    <meta NAME="Keywords" CONTENT="">
    <meta NAME="Description" CONTENT="">
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
    function sure() {
    var val = "#" + $("#txt")[0].value;
    //alert(val);
    $(document.body).css( "background", val);

    //其方法类似于innerHTML,不过是jq专用的innerHTML
    //alert($("#txt").html());
    }
    </script></HEAD><BODY>
    设置网页背景色为<input type="text" value="" id="txt"/>
    <input type="button" value="确定" onclick="sure();" />
    </BODY>
    </HTML>
      

  3.   

    谢谢各位兄弟姐妹,但是我的问题你们可能没有理解。我做的是html编辑器,最终我需要把整个html文本保存起来的。通过javascript 可以设置元素的style属性。但是不能保存呀。
    还有就是 xiaofan_sap,如果可以实现的话,麻烦您说明白一点。
    chen_xiaoguo,你应该理解我的意思,但是资源分不够,下不来,哈哈