简体   繁体   English

没有在Grails GSP中呈现的javascript

[英]javascript not rendered in Grails GSP

I'm using Grails 1.3.7 and jQuery Mobile. 我正在使用Grails 1.3.7和jQuery Mobile。 I need to execute the following Javascript to initialize a select for a specific page but firebug confirms that this code is not being included when the page is rendered even though g:layoutHead in the layout is rendering the meta and title tags that are also in the head for this page. 我需要执行以下Javascript来初始化特定页面的选择,但是即使布局中的g:layoutHead呈现了也在页面中的meta和title标签,firebug仍确认在呈现页面时不包含此代码。前往此页面。

<g:javascript>
    var zselect = document.getElementById('tee')
    var zopt = zselect.options[zselect.selectedIndex]
</g:javascript>

Any idea why the script is not being rendered? 知道为什么不渲染脚本吗?

The head of my layout has the jQuery and jQuery Mobile includes as well as the jQuery UI datepicker and fluid960. 我的布局负责人包括jQuery和jQuery Mobile以及jQuery UI datepicker和fluid960。 Here's the end of the layout head: 这是布局头的结尾:

    <g:layoutHead/>
</head>

Here's the head of the view from which the meta and title tags are rendered but not the javascript. 这是呈现meta和title标签的视图的头部,而不是javascript。

<head>
  <g:javascript>
    var zselect = document.getElementById('tee')
    var zopt = zselect.options[zselect.selectedIndex]
  </g:javascript>
  <meta name="layout" content="main">
  <g:set var="entityName" value="${message(code: 'foursome.label', default: 'Foursome')}"/>
  <title><g:message code="default.create.label" args="[entityName]"/></title>
</head>

Maybe its in your <head> section of the GSP, but your layout doesn't have a <g:layoutHead/> tag? 也许它在GSP的<head>部分中,但是您的布局没有<g:layoutHead/>标记?

Checkout the Layout documentation for more info . 请查看布局文档以获取更多信息

If you look in the rendered html, is the Javascript there? 如果查看呈现的html,是否存在Javascript?

If it is, I think your problem is, that you try to reference objects on in you DOM from the header, before the DOM is rendered. 如果是这样,我想您的问题是,您尝试在呈现DOM之前从标头中引用DOM中的对象。 You would have to move your initialization code to the bottom of your GSP, to make sure that the entire DOM is loaded. 您必须将初始化代码移至GSP的底部,以确保加载了整个DOM。 Or, you could use the onLoaded feature of jQuery. 或者,您可以使用jQuery的onLoaded功能。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM