最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - unterminated string literal error for a django template tag - Stack Overflow

programmeradmin4浏览0评论

I have the following snippet of code which gives me unterminated string literal error

$(function() {
             $('#addDropdown').click(function() {
             var $d = $('{{ form |bootstrap }}').fadeIn().delay(1000);   
             $('#dropdownContainer').append($d);
             });
             });

I have looked unterminated string literal question and found that it is because multiline problem.My {{ form |bootstrap }} has multiple lines of code as mentioned in the question.So how do I handle the problem

I have the following snippet of code which gives me unterminated string literal error

$(function() {
             $('#addDropdown').click(function() {
             var $d = $('{{ form |bootstrap }}').fadeIn().delay(1000);   
             $('#dropdownContainer').append($d);
             });
             });

I have looked unterminated string literal question and found that it is because multiline problem.My {{ form |bootstrap }} has multiple lines of code as mentioned in the question.So how do I handle the problem

Share Improve this question edited May 23, 2017 at 12:01 CommunityBot 11 silver badge asked Jun 18, 2014 at 11:25 iLoveCamelCaseiLoveCamelCase 47010 silver badges21 bronze badges 3
  • add }); at the end of code as this is to close your $(function(){ – Bhushan Kawadkar Commented Jun 18, 2014 at 11:26
  • I think you want to render the form somewhere else than in the javascript and then just find it via some class/id selector and call fadeIn() on the found element – yedpodtrzitko Commented Jun 18, 2014 at 11:28
  • I want to add multiple(unknown number given by user by button clicks) forms to a div.Each form contains a dropdown.Fade in is just to show the transition of adding the element smoothly. – iLoveCamelCase Commented Jun 18, 2014 at 11:31
Add a ment  | 

1 Answer 1

Reset to default 10

In general, to use with JavaScript, you should use |escapejs filter:

var $d = $('{{ value|escapejs }}');

However, as a matter of best practice you'd better put {{ form|bootstrap }} in HTML, and use JavaScript just to fade in:

<div id="djangoForm" style="display:none">{{ form|bootstrap }}</div>
<script>
    $('#addDropdown').click(function() {
         $('#dropdownContainer').append($('#djangoForm'));
    }
</script>
发布评论

评论列表(0)

  1. 暂无评论