代码之家  ›  专栏  ›  技术社区  ›  my_name

用jquery做奇怪事情的url\u

  •  0
  • my_name  · 技术社区  · 8 年前

    我目前正在努力使用python/flask/Jquery! 我想使用 URL_for 函数 img 标签,但当使用它时,浏览器会做出奇怪的事情!

    $("div.left").append("<img id='my_img' class='centered' style='width:100%; height:100%' src=" + "{{ url_for('static', filename='./img/logo.png') }}" + "alt='Loading error!' />")
    

    这是浏览器给我的:

    <img id="my_img" class="centered" style="width:100%; height:100%" src="/static/img/logo.pngalt='Loading" error!'="">
    

    js 文件的url为(似乎不适合我!)?

    2 回复  |  直到 8 年前
        1
  •  2
  •   uedemir    8 年前

    我认为这个问题是由双引号和单引号引起的。你能试试吗;

    $("div.left").append('<img id="my_img" class="centered" style="width:100%; height:100%" src="{{url_for("static", filename="./img/logo.png")}}" alt="Loading error!" />')
    
        2
  •  0
  •   Vinoth Marieswaran    8 年前

    $(function() {
      $("div.left").append("<img id='my_img' class='centered' style='width:100%; height:100%' src='" + url_for('static','./img/logo.png')+"' alt='Loading error!' />")
    });
    
    function url_for(a,b){
        return b;
    }