简体   繁体   English

为什么脚本元素中的代码无法运行?

[英]Why does my code in a script element not run?

I have the following script in my smarty template: 我的smarty模板中包含以下脚本:

<script src="http://code.jquery.com/jquery-latest.js">
    $(document).ready(myBookings);
</script>

However it doesn't work on page load. 但是,它不适用于页面加载。 $(document).ready(myBookings); does work when I run it in Mozilla firebug console though. 确实可以在Mozilla firebug控制台中运行它。 What am I doing wrong? 我究竟做错了什么?

script elements can have a src attribute or content, but not both. script元素可以具有src属性内容,但不能同时具有两者。 If they have both, the content is ignored (the content is considered "script documentation," not code). 如果两者兼有,则将忽略内容(该内容被视为“脚本文档”,而不是代码)。

Use another script block for your document-ready handler 为您的文档就绪处理程序使用另一个脚本块

<script src="http://code.jquery.com/jquery-latest.js">
</script>
<script>
    $(document).ready(myBookings);
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的脚本不能在 AJAX 刷新时运行? - Why does my script not run on AJAX refresh? 为什么我的 JavaScript forEach 重复两个元素然后 setAttribute 值到第三个元素代码只运行一次? - Why does my JavaScript forEach muliplication of two elements then setAttribute value to a third element code only run once? 我的 php 代码不在 html 脚本标签中运行 - my php code does not run in the html script tag 除非我更改脚本文件的顺序,否则我的代码不会运行 - My code does not run unless I change the order of a script file 为什么设置数组元素的值会导致我的脚本失败? - Why does setting the value of an array element cause my script to fail? 为什么我的 Google App 脚本自动刷新代码不起作用? - Why does my Google App script auto refresh code not work? 为什么我在 javascript 中的 for 循环代码只运行一次? - Why does my for-loop code in javascript only run once? 为什么确认后我的 onclick 事件中的代码没有运行? - Why does the code in my onclick event after a confirm not run? 有谁知道为什么我的代码,特别是 javascript 不会运行? - does anyone know why my code, specifically the javascript wont run? 为什么此脚本永远不会运行? - Why does this script never run?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM