How to ensure the javascript is at the bottom of the code in Jade template?

我是研究僧i 提交于 2019-12-08 03:17:26

You can define more blocks in your layout to fill. You can even define default values for blocks: see http://jade-lang.com/reference/extends/

layout.jade:

html
  head
    meta(charset='UTF-8')
    title MyApplication
    meta(content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no', name='viewport')
    link(href='/bootstrap/dist/css//bootstrap.min.css', rel='stylesheet', type='text/css')

  body
    block content

    script(src='http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js')
    script(src='/bootstrap/dist/js/bootstrap.min.js', type='text/javascript')

    block script

home.jade:

extends layout

block content

        // Content Header (Page header)
        section.content-header
          h1= title

        // Main content
        section.content

block script
    script(type='text/javascript').
      $(function() {
        alert('here!');
      }

This will render your content, js libraries and your script respectively.

In layout.jade, indent script tags inside body.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!