dqf42223 2013-06-08 17:38
浏览 207

无法编译.tpl文件中的JS

I have the following code inside my .tpl file (I am using the Smarty template engine for my project).

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
   <script>
          $(document).ready(function(){
    $('.check:button').toggle(function(){
        $('input:checkbox').attr('checked','checked');
        $(this).val('uncheck all');
    },function(){
        $('input:checkbox').removeAttr('checked');
        $(this).val('check all');        
    })
})
</script>

<input type="button" class="check" value="check all" />

   <input type="checkbox" class="cb-element" /> Checkbox  1
   <input type="checkbox" class="cb-element" /> Checkbox  2
   <input type="checkbox" class="cb-element" /> Checkbox  3

However, in the final compiled php code, the JS function doesn't appear, as a result of which the toggle ("check all") button I want to create doesn't work. The final compiled php code, as seen in the browser looks like this :

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
   <script>
          $(document).ready(function(),function())
})
</script>

<input type="button" class="check" value="check all" />

   <input type="checkbox" class="cb-element" /> Checkbox  1
   <input type="checkbox" class="cb-element" /> Checkbox  2
   <input type="checkbox" class="cb-element" /> Checkbox  3

I am new to using both jQuery and Smarty. Any help would be greatly appreciated. The jQuery function has been discussed in this SO post.

EDIT : I have put the JS inside {literal} and {/literal} and I can now see the JS function in the finally compiled php code. However, the JS function still does not respond! Why might that be?

  • 写回答

2条回答 默认 最新

  • dpi9530 2013-06-08 18:15
    关注

    Consider putting your JS in separate file and linking to it. Smarty uses { and } as special characters.

    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)