添加< style>和< script>从身体上放在头上 [英] Add <style> and <script> from body and place it on head

查看:326
本文介绍了添加< style>和< script>从身体上放在头上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为此主题使用Spring Roo 1.2.4.我知道要添加用户定义的默认样式和脚本,应在PROJECT_FOLDER/src/main/webapp/WEB-INF/tags/util/load-scripts.tagx上添加.就我而言,我有一些.jspx仅在特定视图上需要其他样式和脚本.

I am using Spring Roo 1.2.4 for this topic. I am aware that to add user-defined default styles and scripts should be added on PROJECT_FOLDER/src/main/webapp/WEB-INF/tags/util/load-scripts.tagx. In my case, I have some .jspx that need(s) additional style and scripts on a particular view only.

<罢工> 当我在.jspx文件上使用<style><script>标记查看页面时,<style>会被渲染并相应地工作.但是<script>标记尤其在使用JQuery库进行对话框时不起作用. 我已将jquery库添加到webapp下的scripts文件夹中.

When I view the page with the <style> and <script> tags on the .jspx file, the <style> gets rendered and work accordingly. But the <script> tag doesn't work especially when using the JQuery library for dialog. I have added the jquery libraries on the scripts folder under webapp.

已得到修复,因为jquery.js是在jquery-ui.js下面呈现的,其中jquery.js应该首先呈现.

Already fixed because jquery.js was rendered below jquery-ui.js in which jquery.js should be rendered first.

由于HTML标准,可能不建议在正文部分使用<style><script>标记.有没有一种方法可以将特定.jspx上的<style><script>标签呈现在<head>部分上,而不是将它们呈现在<body>部分上?

Having a <style> and <script> tag in the body section might not be advisable due to HTML standards. Is there a way to have the <style> and <script> tags on a particular .jspx be render on the <head> section instead of having them rendered on the <body> section?

推荐答案

Java

我认为我要做的是以下3个步骤.我的解决方案基于某些页面如何定义菜单而有些页面没有菜单.相同的基本原理.

I think what i would do is the following 3 steps. I based my solution on how some pages can have the menu defined and some dont'. Same basic principle.

也就是说,在/src/main/webapp/WEB-INF/layouts/default.jspx内,添加一个带有ignore = true的tile:insertAttribute标记,例如以下内容:

That is, inside of /src/main/webapp/WEB-INF/layouts/default.jspx, add the a tiles:insertAttribute tag with ignore=true, such as following to the head:

    <!-- FIXME Can't move scripts to the bottom of 
      page because of how spring tags do the fields-->
    <util:load-scripts />
    <tiles:insertAttribute name="pagespecificscripts" ignore="true" />

    <spring:message code="application_name" var="app_name" htmlEscape="false"/>
    <title><spring:message code="welcome_h3" arguments="${app_name}" /></title>
</head>

将特定于页面的脚本添加到与视图相同的文件夹中

也就是说,如果您的实体名为披萨",则将以下内容添加到/src/main/webapp/WEB-INF/views/people:

Add the page specific scripts to the same folder as the view

That is, if your entity is named "pizza", add the following to /src/main/webapp/WEB-INF/views/people :

<jsp:root xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:spring="http://www.springframework.org/tags" version="2.0">
    <script src="http://code.jquery.com/jquery-1.9.1.min.js" type="text/javascript"><!-- required for FF3 and Opera --></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js" type="text/javascript"><!-- required for FF3 and Opera --></script>
    <script type="text/javascript" src="http://www.alpacajs.org/js/alpaca.min.js"><!-- required for FF3 and Opera --></script>
    <script src="${areYouSure_js}" type="text/javascript"><!-- required for FF3 and Opera --></script>
    <link type="text/css" href="http://www.alpacajs.org/css/alpaca.min.css" rel="stylesheet"/>
</jsp:root>

在views.xml中定义图块定义属性

更新特定于实体的图块views.xml以设置我们在步骤1中定义的可选属性.也就是说,将以下内容添加到/src/main/webapp/WEB-INF/views/people/views.xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN" "http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
<tiles-definitions>
    <definition extends="default" name="people/list">
        <put-attribute name="body" value="/WEB-INF/views/pizza/list.jspx"/>
        <put-attribute name="pagespecificscripts" value="/WEB-INF/views/pizza/pagespecificscripts.jspx"/>
    </definition>

这些步骤应该可以助您一臂之力.

Those steps should get you on your way.

希望有帮助...

这篇关于添加&lt; style&gt;和&lt; script&gt;从身体上放在头上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆