gpt4 book ai didi

javascript - 如何调用这个文件中的函数?

转载 作者:行者123 更新时间:2023-11-30 08:17:03 25 4
gpt4 key购买 nike

我将此链接中给出的代码粘贴到名为 md5.js 的文件中。

http://www.webtoolkit.info/javascript-md5.html

我无法在下面的代码中调用函数。请帮助我。

<p></p>


function inc(filename)
{
var body = document.getElementsByTagName('body').item(0);
script = document.createElement('script');
script.src = filename;
script.type = 'text/javascript';
body.appendChild(script)
}

function CheckCaptcha()
{
var CaptchaWord="";

CaptchaWord = document.getElementById('studentusername').value;
inc("md5.js");

//Add MD5 function here.
}


<p></p>

最佳答案

您可以尝试为 onload 脚本添加一个事件处理程序并从那里继续您的代码。

例如

function inc(fname, callback)
{
var body = document.getElementsByTagName('body').item(0);
script = document.createElement('script');
script.src = filename;
script.type = 'text/javascript';
script.onload = callback;
body.appendChild(script);
}

function CheckCaptcha()
{
var CaptchaWord="";

CaptchaWord = document.getElementById('studentusername').value;
inc("md5.js", function() {
//Add MD5 function here.
});

}

这种方法的替代方法(也将更有效地工作)是直接包含 md5 脚本,而不是使用 inc 函数。

<script src="/path/to/md5.js" type="text/javascript"></script>
<script type="text/javascript">
function CheckCaptcha()
{
var CaptchaWord="";
CaptchaWord = document.getElementById('studentusername').value;
return md5(CaptchaWord); //or something
}
</script>

关于javascript - 如何调用这个文件中的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1605748/

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