[JavaScript] [object CSSStyleDeclaration] abfragen

Dieses Thema im Forum "Webentwicklung" wurde erstellt von onip, 1. Juli 2009 .

Status des Themas:
Es sind keine weiteren Antworten möglich.
  1. 1. Juli 2009
    [object CSSStyleDeclaration] abfragen

    hi,

    möchte eine kleine erweiterung für den spaw editor machen.
    dabei würde ich gern die styles eines elements abfragen.

    das element in spaw
    PHP:
    < div id = "xxx"  style = "border: 0; color: #000;"  class= "yyy" > utuztuzt </ div >
    js
    PHP:
    var  aProps  spawArguments ;
    alert  ( aProps . style );
    ausgabe
    PHP:
    [ object CSSStyleDeclaration ]
    wie kann ich style in einen string ausgeben?
     
  2. 1. Juli 2009
    AW: [object CSSStyleDeclaration] abfragen

    .toString ?
     
  3. 1. Juli 2009
    AW: [object CSSStyleDeclaration] abfragen

    .toString() hab ich auch schon probiert, geht nicht.
     
  4. 1. Juli 2009
    AW: [object CSSStyleDeclaration] abfragen

    Mit JQuery geht es ziemlich einfach, mit der Funktion css(name):
     
  5. 1. Juli 2009
    AW: [object CSSStyleDeclaration] abfragen

    mit mootools auch, will aber jetzt nicht anfangen spaw umzuschreiben.
    so wie es aussieht komm ich um eine schleife nicht drum herum.
    hab gehofft, dass ich wie

    PHP:
    aProps . id
    oder
    aProps
    . className
    den wert erhalte.
     
  6. 1. Juli 2009
    AW: [object CSSStyleDeclaration] abfragen

    Ich verstehe das Problem noch nicht:
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function bsp()
    {
    alert(document.getElementById('test').style.width);
    alert(document.getElementById('test').style.fontSize);
    }
    </script>
    </head>
    <body onload="bsp()">
    <div id="test" style="width: 300px; font-size: 14pt;">TEXT</div>
    </body>
    </html>
    Funktioniert doch.
     
  7. 1. Juli 2009
    AW: [object CSSStyleDeclaration] abfragen

    ja stimmt, aber wenn ich nicht weiß was drin steht, dann kan ich das auch nicht abfragen

    hab's erstmal so gemacht
    PHP:
    styleAr  = [ "background" "backgroundAttachment" "backgroundColor" "backgroundImage" "backgroundPosition" "backgroundRepeat" "border" "bottom" "captionSide" "clear" "clip" "color" "cursor" "direction" "display" "emptyCells" "cssFloat" "font" "fontFamily" "fontSize" "fontStretch" "fontStyle" "fontVariant" "fontWeight" "height" "left" "letterSpacing" "lineHeight" "listStyle" "listStyleImage" "listStylePosition" "listStyleType" "margin" "maxHeight" "maxWidth" "minHeight" "minWidth" "overflow" "padding" "pageBreakAfter" "pageBreakBefore" "position" "right" "scrollbar3dLightColor" "scrollbarArrowColor" "scrollbarBaseColor" "scrollbarDarkshadowColor" "scrollbarFaceColor" "scrollbarHighlightColor" "scrollbarShadowColor" "scrollbarTrackColor" "tableLayout" "textAlign" "textDecoration" "textIndent" "textTransform" "top" "verticalAlign" "visibility" "width" "wordSpacing" "zIndex" ];

    styletxt  '' ;
        for (
    0 styleAr . length i ++){
            
            if (
    aProps . style [ styleAr [ i ]]){
                
    styletxt  +=  styleAr [ i ]+ ': ' + aProps . style [ styleAr [ i ]]+ ";" ;
            }
        }
        if (
    styletxt  !=  "" ) {
          
    document . getElementById ( "style" ). value  styletxt ;
        }
     
  8. 1. Juli 2009
    AW: [object CSSStyleDeclaration] abfragen

    .cssText <- alle formate drinnen als string. vorsicht diese eigenschaft hat nen setter!
     
  9. 2. Juli 2009
    AW: [object CSSStyleDeclaration] abfragen

    so einfach kann es sein.

    PHP:
    alert ( aProps . style . cssText );
    danke @all
     
  10. Video Script

    Videos zum Themenbereich

    * gefundene Videos auf YouTube, anhand der Überschrift.