我有一段 javascript/jquery 代码,当页面加载时,它会在文档之间执行。
它的作用是获取特定 div 的高度,并将其分配给另一个 div。
这在 Firefox 中运行良好,但在所有其他浏览器(Chrome、Opera、Safari、IE)的最新版本中失败。我使用的是 Windows 7 Home Premium 64 位。
这是代码。当页面生成
时,它位于div
下方。仅适用于 Firefox,其他均无效。
'<script type="text/javascript;">'.
'$(document).ready(function() {'.
'$(\'.s\').height($(\'.entry\').height());'.
'});'.
'</script>'.
最佳答案
认为问题在于您指定的类型值。 type
属性值末尾有一个额外的 ;
。
因此,要么将其更改为 text/javascript
,要么完全删除 type 属性
This attribute identifies the scripting language of code embedded within a script element or referenced via the element’s src attribute. This is specified as a MIME type; examples of supported MIME types include
text/javascript
,text/ecmascript
,application/javascript
, andapplication/ecmascript
. If this attribute is absent, the script is treated as JavaScript.
关于文档之间的 Javascript 和 jQuery 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26192887/