开发者

How do I put Javascript in the <head> element of a Coldfusion Model Glue page?

I have a Model Glue CFM page index.cfm with some JS code that I'd like to execute:

<script type="text/javascript">
    $(function() {
        $('#text').height(300);
    });
</script>

<p id="text">This is some text</p>

This is being inserted into a CFM template that looks like this:

<html>
    <head>
        <script type="text/javascript" src="js/jquery.js"></script>
    </head>

    <body>
        <cfoutput>#viewCollection.getView("body")#</cfoutput>
    </body>
</html>

And the relevant part in ModelGlue.xml:

<event-handler name="page.index">
    <views>
        <include name="body" template="pages/index.cfm"/>
        <include name="main" template="templates/main.cfm"/>
    </views>
</event-handler>

Unfortunately, this will stick the Javascript portion directly into the body. Is there a way to put it in the <head> tag without 开发者_运维问答having to create a separate CFM file, similar to how the ASP.NET MVC 3 Razor @section tag works?


You can use <cfhtmlhead>

For more details, see the docs here.


You can put JavaScript code in head section of Master.Layout.cfm. you can also put on body section in page from where you are calling JavaScript function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜