herostark 2016-08-16 03:51 采纳率: 0%
浏览 1052

jQuery 同时出现 atrr() 和 data() 是为了兼容性问题吗?

        jQuery(clipPathN).attr({
            'data-boxwidth' : boxW,
            'data-boxheight': boxH,
            'data-shapid'   : 'shapId' + clss,
            'data-shaperatiochk': jQuery('#shapeRatioChk').prop('checked')
        });
        jQuery(clipPathN).data({
            'boxwidth' : boxW,
            'boxheight': boxH,
            'shapid'   : 'shapId' + clss,
            'shaperatiochk': jQuery('#shapeRatioChk').prop('checked')
        });

  • 写回答

2条回答 默认 最新

  • 斯洛文尼亚旅游 2016-08-16 04:02
    关注

    attr是设置dom对象的属性(attribute),就是

     <div id="xx" aa="自定义aa属性"
    

    里面的aa,id属性,值只能为字符串

    data是在dom对象上缓存数据,可以为对象之类的数据

    http://www.w3school.com.cn/jquery/data_jquery_data.asp

    prop方法是设置dom对象的property,注意和attr的区分
    jquery attr prop 区别

    评论

报告相同问题?