尝试从谷歌翻译API开始使用并使用ready()

Trying to start with google translate API and using ready()

本文关键字:ready 开始 谷歌 翻译 API      更新时间:2023-09-26

我有这个代码:

<script language="javascript" src="http://www.google.com/jsapi"></script>
<script language="javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.js"></script>
<script language="javascript">
 $(document).ready(function() { 
 } );
</script>
</head>
<body>
<form onsubmit="return false">
 <input type="button" value="Translate" onclick="gtrans(this.form)" />
 <p id="translation" style="border:1px solid #00f;padding:5px;width:400px">-</p>
</form>
</body>

当我在ready(){}内添加该行时,google.load ("language", "1");表单没有显示,为什么?

问候

哈维

$(document).ready() 函数在窗口加载之前执行,只要浏览器注册了 DOM。因此,正如 Dalen 所建议的那样,您应该将代码放在函数之外。