Javascript会移除结束<a> tag?

时间:2016-06-10 10:03:42

标签: javascript

I'm having a strange problem with one of my scripts. In the script parameters I'm trying to creating a link which makes up for the "read more" link on the frontend. Using the Jed Foster Read More script I'm trying to override the default "moreLink" and "lessLink" as was documented.

The default setting works perfect but when an override in the parameters is used somehow the closing tag is removed and the link is parsed empty.

This is how the script looks like:

<script type="text/javascript" src="{{ url('gantry-theme://js/readmore.js') }}"></script>
<script type="text/javascript">
    var $j = jQuery.noConflict();
    {% if particle.title %}
    var $dropspeed = {{ particle.dropdownspeed|raw }};
    var $collapsedheight = {{ particle.collapsedheight|raw }};
    var $readmore = '<a href="#">"Read Moreeeee"</a>;
    $j(document).ready(function() {
        $j('.g-employee-text').readmore({
          speed: $dropspeed,    
          collapsedHeight: $collapsedheight,
          heightMargin: 30,
          moreLink: '<a href="#">Read More</a>',
        });
    });
    {% endif %}
</script>

And this is how its shown in the developer tools:

var $j = jQuery.noConflict();
            var $dropspeed = 3000;
    var $collapsedheight = 150;
    var $readmore = '<a href="#">"Read Moreeeee";
    $j(document).ready(function() {
        $j('.g-employee-text').readmore({
          speed: $dropspeed,    
          collapsedHeight: $collapsedheight,
          heightMargin: 30,
          moreLink: '<a href="#">Read More',
        });
    });

As you can see the closing tag is not available. The HTML looks as follows:

<a href="#" data-readmore-toggle="rmjs-1" aria-controls="rmjs-1"></a>

An empty link doing nothing.

Some notable information:

  • Read More script by Jed Foster
  • Gantry 5 framework

Hope someone can help me out here.

1 个答案:

答案 0 :(得分:0)

var $readmore = '<a href="#">"Read Moreeeee"</a>;

为什么需要双引号? 你试过删除它们吗?

var $readmore = '<a href="#">Read Moreeeee</a>;