Get attributes from the rel attribute with jQuery

后端 未结 3 1971
名媛妹妹
名媛妹妹 2021-01-23 14:31

Im using a plugin that requires the rel-element to look like this.

3条回答
  •  悲哀的现实
    2021-01-23 14:47

    Superbly ugly, but you can use the dreaded eval(), provided that the rel data are "well-formed":

    $(function() {
        $('a').mouseover(function() {
            eval('var rel = {' + $(this).attr('rel') + '};');
            $('#out').text(rel.smallImage);
        });
    });
    

    With HTML:

    
    

    Demo.

提交回复
热议问题