gpt4 book ai didi

javascript - '$.md5 is not a function'之谜

转载 作者:行者123 更新时间:2023-11-28 04:18:47 25 4
gpt4 key购买 nike

我有一个使用 jQuery.MD5 库的 js 代码。它在我的服务器上完美运行:

<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://example.com/static/js/jquery.md5.js"></script>
</head>
<body>
<script>
// my code goes here (declaring variables and functions)
var code = $.md5('mystring');
// and a little more code
</script>
</body>

但随后我将其上传到网络应用程序(我无法控制),这使得它看起来像这样并将其放入 iframe 中:

<head>
<script>
// some extra variables are declared here
// double-checked that nothing here can break my code
</script>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://example.com/static/js/jquery.md5.js"></script>
<script>
// some code
var code = $.md5('mystring');
// some code
</script>
</body>

这段代码开始给出 $.md5 is not a function 错误。奇怪的事情。尝试清除缓存,将 jquery.md5.js 代码直接放入我的代码中,但没有任何效果。

请注意,所有代码都可以在我的机器上运行,因此我的 JS 一定没有问题

更新:有问题的代码行为似乎是不可预测的,这意味着有时无需更改即可正常工作。

可能出了什么问题?

最佳答案

嗯...这有点尴尬,但问题出在 jQuery 中。我在 iframe 中包含的内容与页面中包含的内容冲突。不知何故,这导致我的 $.md5 函数在代码结束后“隐藏”。

是的,我知道,很明显 jQuery 可能会导致问题。

关于javascript - '$.md5 is not a function'之谜,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45618236/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com