Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
加载细枝模板后执行javascript_Javascript_Jquery Mobile_Symfony_Twig - Fatal编程技术网

加载细枝模板后执行javascript

加载细枝模板后执行javascript,javascript,jquery-mobile,symfony,twig,Javascript,Jquery Mobile,Symfony,Twig,我使用的是Symfony 2,我需要在加载以下小树枝模板之后执行javascript: <div data-role="dialog"> <div data-role="header"> <h1>Input your Username and Password</h1> </div> <div data-role="content"> <div data-

我使用的是Symfony 2,我需要在加载以下小树枝模板之后执行javascript:

<div data-role="dialog">
    <div data-role="header">
        <h1>Input your Username and Password</h1>
    </div>
    <div data-role="content">
            <div data-role="fieldcontain" class="ui-hide-label">
                <label for="username">Username:</label>
                <input type="text" name="username" id="username" value="" placeholder="Username"/>
            </div>
            <div data-role="fieldcontain" class="ui-hide-label">
                <label for="password">Password:</label>
                <input type="password" name="password" id="password" value="" placeholder="password" />
            </div>
            <div data-role="controlgroup" data-type="horizontal" align="center">
                <input type="button" value="Login"/>
                <a data-rel="back" data-role="button"/>Cancel</a>
            </div>
    </div>
</div>

输入您的用户名和密码
用户名:
密码:
取消

在模板底部添加

<script type="text/javascript">
    window.onload = function() {
       //do your stuff here
    }
</script>

window.onload=函数(){
//在这里做你的事
}
或者如果您使用的是jQuery

<script type="text/javascript">
    $(function() {
        //do your stuff here
    });
</script>

$(函数(){
//在这里做你的事
});

$(“#divId”).live('pageinit',
功能(事件)
{
});

通常,当我们使用jquery mobile时,页面的主容器是一个带有datarole的div,为这个div设置一个id,并用上面脚本中的divid替换它,然后让代码正常工作:-)

首先,我在这里没有看到任何twig变量。关于加载部分,在服务器端呈现twig模板,然后将呈现的html发送到客户端。所以如果你想在模板加载后执行JS,我想你的意思是在页面加载后??为此,您只需添加“…您的js…”在你的html之后,将代码链接到页面加载事件。这与细枝无关。什么不起作用?如果您查看页面源代码,代码在那里吗?使用jquery mobile时,页面之间的切换是不同的,但是谢谢,我设法让它工作了,我发布了答案:)
<script type="text/javascript">
        $("#divId").live( 'pageinit',
        function(event)
        {
        });
</script>