JTemplates escape {$

Is there a way with jTemplates to exit {$, so I can use the built-in javascript in my onBlur, for example

<a href="http://www.telegraaf.nl" onclick="if ( a ) {$('#something').css    ('display','none');alert('some msg');}">telegraaf</a>

which gets this after processTemplate:

<a onclick="if ( a ) " href="http://www.telegraaf.nl">

Thanks Henk

+3
source share
5 answers

jTemplates has a tag {#literal} ... {# / literal}, which should prevent curly braces from hanging.

<a href="http://www.telegraaf.nl" onclick="{#literal}if ( a ) {$('#something').css    ('display','none');alert('some msg');}{#/literal}">telegraaf</a>
+8
source

Actually, in my opinion, I believe that it is best to attach this event unobtrusively:

$(function () {
    $(".alink").click(function () {
        //if ( a ) {
            $('#something').css('display','none');
            alert('some msg');
        //}   
    });
});

<a class="alink" href="http://www.telegraaf.nl">
+3
source

jQuery, $ jQuery (), :

<a href="http://www.telegraaf.nl" onclick="if ( a ) {jQuery('#something').css    ('display','none');alert('some msg');}">telegraaf</a>

http://docs.jquery.com/%24

-1

If you do not want to move JS to separate a section or an external file, you can always use jQuery"keyword" instead$

<a href="http://www.telegraaf.nl" onclick="if( a ) {jQuery('#something').css('display','none');alert('some msg');}">telegraaf</a>

This method $will not be interpreted as a template variable.

-1
source
var test = function(el) {
   if ( a ) {
      $('#something').css('display','none');
      alert('some msg');
    }   
});

<a onclick="test(this);" href="http://www.telegraaf.nl">
-2
source

Source: https://habr.com/ru/post/1714500/


All Articles