Site Notice

hello, world

Difference between revisions of "Youdao translate"

From Project-EPB Commons
(Created page with "<html> <label for="origin">原文</label> <textarea id="origin" style="max-width: 100%; min-width: 100%; min-height: 4em"></textarea> <label>翻译</label> <pre id="translatio...")
 
([InPageEdit] 没有编辑摘要)
 
(2 intermediate revisions by the same user not shown)
Line 4: Line 4:
 
<label>翻译</label>
 
<label>翻译</label>
 
<pre id="translation"></pre>
 
<pre id="translation"></pre>
<button onclick="translate">翻&emsp;译</button>
+
<button onclick="translate()">开始翻译</button>
  
<script>window.translate = function() {
+
<script>function translate() {
var text = $('#origon').val();
+
var text = $('#origin').val();
 
if (text === '') return;
 
if (text === '') return;
 
$.ajax({
 
$.ajax({
Line 25: Line 25:
 
})
 
})
 
}
 
}
 +
</script>
 +
</html>

Latest revision as of 21:41, 25 June 2020

<html> <label for="origin">原文</label> <textarea id="origin" style="max-width: 100%; min-width: 100%; min-height: 4em"></textarea> <label>翻译</label> <pre id="translation"></pre> <button onclick="translate()">开始翻译</button>

<script>function translate() { var text = $('#origin').val(); if (text === '') return; $.ajax({

 url: 'https://fanyi.youdao.com/openapi.do',
 data: {
   keyfrom: 'youdaoci',
   key: '694691143',
   type: 'data',
   doctype: 'jsonp',
   version: '1.1',
   q: text
 },
 dataType: 'jsonp'

}).done((data)=>{

 var translation = data.translation[0];
 $('#translation').text(translation);

}) } </script> </html>