Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jquery替换参数_Javascript_Jquery_Python_Jinja2 - Fatal编程技术网

Javascript 使用jquery替换参数

Javascript 使用jquery替换参数,javascript,jquery,python,jinja2,Javascript,Jquery,Python,Jinja2,我正在与python和jinja合作。渲染模板时,我发送了如下两个参数: return render_template('mod_page/index.html', types_first = utils.questions_first(), types_second = utils.questions_second()) questions\u first和questions\u second是两个相同的函数,如下所示:

我正在与python和jinja合作。渲染模板时,我发送了如下两个参数:

return render_template('mod_page/index.html', 
                types_first = utils.questions_first(), 
                types_second = utils.questions_second())
questions\u first
questions\u second
是两个相同的函数,如下所示:

 def questions_first(self):
     return ['Name','Surname', 'Phone'] 
<script>
$(document).ready(function(e){
  var language = $('html').attr('lang');
  var selectedFunction;
  if(language == "sq"){ 
    selectedFunction = "sq";}
  else{
    selectedFunction = "sr"; }
</script>

....
    <p> Questions: </p>
    {{ _({% for type in types_first %}) }}
    <div class="checkbox">
        <label><input type="checkbox" value="{{ type }}">{{ type }}</label>
    </div>
    {% endfor %} 
在索引页中,我有这样一个标记:

<html lang="en">
...
第一个解决方案(更好):

如果要更改lang,可以使用i18next framework()。这是一个简单得多的解决方案

第二种解决方案(更糟):

通过要更改的jQuery元素选择->使用empty()函数->使用更改的值呈现元素,并使用append()将其分配给选择器

您还可以将这两种解决方案结合起来。将函数写入重新加载模板并动态更改语言。e、 g:

fn_or_elt.empty();
fn_or_elt.append(markup);
fn_or_elt.i18n();

我已经实现了更改语言,正如我所说,参数lang可以是:en或sr。基于此,我想更改jinja中的参数@您可以选择输入并用jQuery替换值,但我建议使用Nunjucks,它是jinja2的端口,支持客户端渲染()。