【问题标题】:convert script from jQuery 1.9 to 1.8将脚本从 jQuery 1.9 转换为 1.8
【发布时间】:2013-07-22 21:30:16
【问题描述】:

此脚本在 jQuery 1.9 中有效,但在 1.8 中无效。如何将此脚本转换为 jQuery 1.8?

NOT Working Demo on jsfiddle

Working Demo on jsfiddle

HTML

<div id="container">
    <div id="c1" class="aaa" style="text-align:right; color:red top:100px; ">child 1</div>
    <div id="c2" class="aaa" style="text-align:left; top:200px; ">child 2</div>
</div>

jQuery 脚本

$("#container").children().each( function () {
    alert("element ID = " + $(this).attr('id'));
    var styleProps = $(this).css(["width", 
                                  "height", 
                                  "color", 
                                  "background-color", 
                                  "text-align", 
                                  "left", 
                                  "top", 
                                  "right", 
                                  "bottom"]);
    $.each(styleProps, function (prop, value) {
        alert(prop + " = " + value);
    });
});

【问题讨论】:

    标签: jquery-1.9 jquery-1.8


    【解决方案1】:

    直到1.9 才实现接受数组的css 函数。

    如果您使用的是 1.8,您可能必须手动完成(一次循环一个值)。

    var styleNames = ["width", "height", "color", ...etc... ];
    
    var i;
    var $elem = jQuery(this);
    for (i = 0; i < styleNames.length; ++i) {
        alert(styleNames[i] + " = " + $elem.css(styleNames[i]));
    }
    

    【讨论】:

    • 再次阅读我的答案。接受数组的 css 函数在 jQuery 1.8 中不可用。我提供的示例工作正常,但您必须实际使用它。
    猜你喜欢
    • 2013-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-05
    • 1970-01-01
    • 2016-09-09
    • 1970-01-01
    相关资源
    最近更新 更多