www.gusucode.com > 运用jQuery实现Ajax无刷新在线查词工具源码程序 > 运用jQuery实现Ajax无刷新在线查词工具/dict/dict/notidy_file/notidy_dict.js
function focus(){ $("#word").focus(); } function sendRequest(){ if($("#word").val()==""){ $("#result").html("<img src=\"icon2.gif\" /> 请输入需要翻译的单词,如“hello”或中文“你好”。"); return; } $.ajax({ url:"http://bolm.cn/apps/dict/getxml.php?q="+$("#word").val(), type:"get", dataType:"xml", timeout:3000, success:function(xml){ var html; html="<span class=\"word\">"+$("#word").val()+"</span>"; html+=" <span class=\"pronounce\">"+$(xml).find("pron").text()+"</span>"; $(xml).find('def').each(function(){ html+=" <span class=\"def\">"+$(this).text()+"</span>"; }); $(xml).find('sent').each(function(i){ html+="<span class=\"orig\">"+$(this).children("orig").text()+"</span>"; html+="<span class=\"trans\">"+$(this).children("trans").text()+"</span>"; }); html+="<div class=\"link\">去其他在线词典搜索:<span style=\"color:#016FA4;font-weight:700\">"+$("#word").val()+"</span> <img src=\"icon1.gif\" /> <a href=\"http://www.iciba.com/"+$("#word").val()+"/\" target=\"_blank\">爱词霸词典</a> "; html+="<img src=\"icon1.gif\" /> <a href=\"http://dict.cn/"+$("#word").val()+".htm\" target=\"_blank\">Dict.CN海词</a> "; html+="<img src=\"icon1.gif\" /> <a href=\"http://www.nciku.com/search/all/"+$("#word").val()+"\" target=\"_blank\">N词酷</a></div>"; $("#result").html(html); }, start:function(xml){ $("#result").html("正在查询中,请稍后..."); }, error:function(xml){ $("#result").html("查询失败,请重试..."); } }); }