var macs = {
getMacAddress : function()
{
document.macaddressapplet.setSep( "-" );
document.write( "Mac Address = " + document.macaddressapplet.getMacAddress() );
}
如何调用这个函数并在网站上显示出来?
这似乎不起作用..
<script type="text/javascript">
document.write(mac.getMacAddress());
</script>
有人帮忙吗?
最佳答案
只需使用macs.getMacAddress();
该函数不返回任何内容。它只是写入文档。如果您希望它返回字符串,请在定义 macs
时将 document.write
替换为 return
。
另外,请注意,在页面加载后调用 document.write
将覆盖当前页面(因为它意味着 document.open)。如果您需要在加载后附加到文档,请使用 DOM 或innerHTML。
关于JavaScript 调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2115690/