添加到<正文>cakePHP 应用程序的标签

发布于 2024-08-16 01:34:56 字数 82 浏览 1 评论 0原文

我有一个应用程序,我需要在两个表单的BODY标签的onLoad事件中调用一些JS。但是,我找不到如何修改它们的标签。有谁知道吗?

坦率

I have an app where I need to call some JS in the onLoad event of the BODY tag of two forms. However, I can't find how to modify the tag for just them. Does anyone know?

Frank

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

草莓酥 2024-08-23 01:34:56

inkedmn 当然为这种情况提供了正确的答案,但一般来说,您可以像这样“传递信息”:(

在views/controller/view.ctp中)

$this->set('bodyAttr', 'onload="something"');

(在views/layouts/default.html中) ctp)

<?php
    if (isset($bodyAttr)) {
        $bodyAttr = " $bodyAttr";
    } else {
        $bodyAttr = null;
    }
?>
<body<?php echo $bodyAttr; ?>>

我经常像这样使用它来向“顶级元素”添加额外的类:

<?php
    if (!isset($docClass)) {
        $docClass = null;
    }
?>
<div id="doc" class="<?php echo $docClass; ?>">

inkedmn certainly has provided the right answer for this case, but in general, you can "hand information up" like this:

(in views/controller/view.ctp)

$this->set('bodyAttr', 'onload="something"');

(in views/layouts/default.ctp)

<?php
    if (isset($bodyAttr)) {
        $bodyAttr = " $bodyAttr";
    } else {
        $bodyAttr = null;
    }
?>
<body<?php echo $bodyAttr; ?>>

I often use it like this to add extra classes to a "top level element":

<?php
    if (!isset($docClass)) {
        $docClass = null;
    }
?>
<div id="doc" class="<?php echo $docClass; ?>">
杯别 2024-08-23 01:34:56

您无需修改​​ body 标记即可在页面加载时执行 Javascript。您可以在适当的情况下在布局中包含类似的内容:

(jQuery)

$("body").load(
    function(){
        // do stuff when the body element is loaded.
    }
);

或者,如果您希望在 document.ready 事件触发时执行代码:

$(function(){
        // do stuff when the document is ready
    }
);

或者,如果您不想使用 jQuery,您可以执行某些操作像这样:

function doStuff(){
    // whatever you want to happen when the load completes
}

window.onload = dostuff;

祝你好运 - 如果这个答案不令人满意,请澄清你的问题。

You don't need to modify the body tag to have Javascript execute when the page loads. You could just include something like this in your layout where appropriate:

(jQuery)

$("body").load(
    function(){
        // do stuff when the body element is loaded.
    }
);

Or, if you want to have the code execute when the document.ready event fires:

$(function(){
        // do stuff when the document is ready
    }
);

Or, if you don't want to use jQuery, you could do something like this:

function doStuff(){
    // whatever you want to happen when the load completes
}

window.onload = dostuff;

Good luck - and please clarify your question if this answer isn't satisfactory.

晨光如昨 2024-08-23 01:34:56

我执行以下操作:

我们在我的身体中应用 $ bodyLoad

<body <? = (isset ($ bodyLoad)? 'onload = \''. $ bodyLoad.' \'',''); ?> >

已经在我的 [action] 中。 Ctp,我执行以下操作:

<? php $ this-> set ('bodyLoad', 'field.focus ();');?>

如果您愿意,您也可以将此代码放入控制器中。

祝你好运

I do the following:

We apply $ bodyLoad in my body

<body <? = (isset ($ bodyLoad)? 'onload = \''. $ bodyLoad.' \'',''); ?> >

Already in my [action]. Ctp, I do the following:

<? php $ this-> set ('bodyLoad', 'field.focus ();');?>

If you want you can also put this code in the controller.

Good luck

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文