jquery in smarty tpl

余生长醉 提交于 2019-12-13 14:11:00

问题


jquery in smarty tpl -- Trying to use jquery to insert a class attribute so that I can CSS style every other list item row with shading. The following code seems as though it should work, but "alt" class is not getting inserted into li tag. Page loads fine -- no problems there. Anyone see something obviously wrong?

{literal}
<script src="{$content_dir}themes/pres2c/js/stripe/jquery-1.7.1.js"></script>
    <script type="text/javascript">
        jQuery(document).ready(function(){
        jQuery(".block_content li:even").addClass("alt");
        });
    </script>
{/literal}

this final webpage source is appearing, just like this, in the head, but still li tags aren't getting touched..

<script src="{$content_dir}themes/pres2c/js/stripe/jquery-1.7.1.js"></script>
    <script type="text/javascript">
        jQuery(document).ready(function(){
        jQuery(".block_content li:even").addClass("alt");
        });
    </script>

回答1:


Try:

{literal}
<script src="{/literal}{$content_dir}{literal}themes/pres2c/js/stripe/jquery-1.7.1.js"></script>
    <script type="text/javascript">
        jQuery(document).ready(function(){
        jQuery(".block_content li:even").addClass("alt");
        });
    </script>
{/literal}



回答2:


it should be

<script src="{$content_dir}themes/pres2c/js/stripe/jquery-1.7.1.js"></script>
<script type="text/javascript">
{literal}
    jQuery(document).ready(function(){
    jQuery(".block_content li:even").addClass("alt");
    });
{/literal}
</script>

This way, {$content_dir} is still a smarty variable. In your case, {$content_dir} is taken literal, instead of the variable



来源:https://stackoverflow.com/questions/9147526/jquery-in-smarty-tpl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!