简体   繁体   English

onclick load {%include'test.html'%}

[英]onclick load {% include 'test.html' %}

I would like to load Jinja2 templating string when user clicks on an element. 我想在用户点击元素时加载Jinja2模板字符串。 for example I have tags like: 例如我有以下标签:

 <div class="one"><a href="#one">One</a></div>
 <div class="two"><a href="#two">Two</a></div>
 <div class="three"><a href="#three">Three</a></div>

only after clicking on One, I must load the bellow string: 只有在单击One之后,我必须加载波纹管字符串:

{% include 'one.html' %}

and after clicking on Two, this string must be loaded: 并且在单击Two之后,必须加载此字符串:

{% include 'two.html' %}

and so on. 等等。 How can I manage this issue? 我该如何处理这个问题? Dynamic content loading when clicking 点击时加载动态内容

You will have to use some JavaScript to achieve that. 您将不得不使用一些JavaScript来实现这一目标。

One solution is to use jQuery load http://api.jquery.com/load/ 一种解决方案是使用jQuery加载http://api.jquery.com/load/

Keep in mind that JavaScript happens in the browser (client-side), while Jinja2 is python-based templating which will occur server-side. 请记住,JavaScript发生在浏览器(客户端),而Jinja2是基于python的模板,它将在服务器端发生。 Showing the template string via JavaScript will not achieve your desired result. 通过JavaScript显示模板字符串将无法实现您想要的结果。 There seem to be two ways of achieving what you want. 似乎有两种方法可以达到你想要的效果。

One option is to output the result of the template when the page loads initially and then display it through some javascript behavior. 一种选择是在页面最初加载时输出模板的结果,然后通过一些javascript行为显示它。 There are many jQuery plugins to achieve this result, one example you may look at is Bootstrap Tabs . 有很多jQuery插件可以实现这个结果,你可以看一下Bootstrap Tabs

Another option, if you don't wish to produce all of the template results when you first load the page, would be to load the result of the templates via ajax. 如果您不希望在第一次加载页面时生成所有模板结果,则另一个选项是通过ajax加载模板的结果。 The ajax request would need have to be served the result of the desired jinja2 template which can then be output into your page. 需要将ajax请求提供给所需的jinja2模板的结果,然后可以将其输出到您的页面中。 jQuery's load provides a simple way to do this. jQuery的加载提供了一种简单的方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 加载webView.loadUrl(“ file:///android_asset/test.html”); 模拟器无法加载手机 - load webView.loadUrl(“file:///android_asset/test.html”); to emulator not load mobile 未通过href://test.html从index.html将Javascript加载到test.html中 - Javascript not loaded in test.html from index.html via href://test.html 如果页面链接类似于 test.html?a=1&amp;b=2 那么加载函数将如何工作以获取 a 的值并加载特定的 div? - if page link is like test.html?a=1&b=2 then how load function will work getting value of a and load particular div? 未捕获的 ReferenceError:图表未在 test.html:11 中定义 - Uncaught ReferenceError: Chart is not defined at test.html:11 在node.js中获取[Cannot GET /test.html] - getting [Cannot GET /test.html] in node.js [.CommandBufferContext]渲染警告:没有纹理绑定到单元1 test.html:1 - [.CommandBufferContext]RENDER WARNING: there is no texture bound to the unit 1 test.html:1 无法获取/test.html-node.js-javascript - Cannot GET /test.html - node.js - javascript 流星上的传单空白屏幕,而不是单个非流星test.html上的传单 - leaflet blank screen on meteor but not on single nonmeteor test.html 错误:ENOTDIR:不是目录,scandir&#39;src / app / test.html&#39; - Error: ENOTDIR: not a directory, scandir 'src/app/test.html' 网页加载后,包含HTML的HTML与onclick javascript不起作用 - Html include another Html with onclick javascript is not working after page load
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM