问题
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