gpt4 book ai didi

html - 用于表和查找表的 Javascript

转载 作者:太空宇宙 更新时间:2023-11-03 17:29:12 25 4
gpt4 key购买 nike

我正在尝试创建一个网站,该网站的每个单元格中都有一个包含汉字的表格。用户单击单个单元格,每个单元格中的字符显示在表格旁边的文本框中。字符序列在查找表中找到,并且在第二个文本框中提供了英文翻译。这是 HTML:

<html>
<head>
<head>
<title>
Practice translation
</title>
<script
src="http://code.jquery.com/jquery-1.9.1.min.js">
</script>
<script
type="text/javascript"
src="Small1.js">
</script>
<meta
http-equiv="Content-Type"
content="text/html; charset=UTF-8">
<link
rel="shortcut icon"
href="/favicon.ico"
type="image/x-icon">
<link
rel="stylesheet"
type="text/css"
href="Small1.css">
<link
rel="shortcut icon"
href="Pallindrome.ico"
type="image/x-icon">
<link
rel="icon"
href="Pallindrome.ico"
type="image/x-icon">
</head>
</head>
<body>
<table style="text-align:center">
<tbody>
<tr>
<td id= “M13” style="text-align:center" title="“duān“ end, extreme; head; beginning" class="yellow">端</td>
<td id= “N13” style="text-align:center" title="“wú, mó“ negative, no, not; KangXi radical 71" class="yellow">无</td>
<td id= “O13” style="text-align:center" title="“zhōng“ end; finally, in the end" color="#f1c232" class="yellow">终</td>
<td id= “P13” style="text-align:center" title="“shǐ“ begin, start; then, only then" class="yellow">始</td>
<td id= “Q13” style="text-align:center" title="“shī“ poetry; poem, verse, ode"class="yellow">诗</td>

</tr>
<tr>

<td id= “M14” style="text-align:center" title="“bǐ, bì, pí, pǐ“ to compare, liken; comparison; than" class="yellow">比</td>
<td id= “N14” style="text-align:center" title="“píng“ flat, level, even; peaceful" class="green" >平</td>
<td id= “O14” style="text-align:center" title="“shǐ“ begin, start; then, only then" class="green">始</td>
<td id= “P14” style="text-align:center" title="“xuán“ beautiful jade; star" class="green">璇</td>
<td id= “Q14” style="text-align:center" title="“qíng“ feeling, sentiment, emotion" class="yellow">情</td>

</tr>
<tr>

<td id= “M15” style="text-align:center" title="“zuò, zuō, zuó“ make; work; compose, write; act, perform" class="yellow">作</td>
<td id= “N15” style="text-align:center" title="“sū“ revive, resurrect; a species of thyme" class="green">苏</td>
<td id= “O15” style="text-align:center" title="“xīn“ heart; mind, intelligence; soul" class="red" >心</td>
<td id= “P15” style="text-align:center" title="“jī“ pearl that is not quite round" class="green">玑</td>
<td id= “Q15” style="text-align:center" title="“míng“ bright, light, brilliant; clear" class="yellow">明</td>

</tr>
<tr>

<td id= “M16” style="text-align:center" title="“lì, lí“ beautiful, magnificent, elegant" class="yellow">丽</td>
<td id= “N16” style="text-align:center" title="“shì, zhī, jīng“ clan, family; mister" class="green">氏</ td>
<td id= “O16” style="text-align:center" title="“shī“ poetry; poem, verse, ode" class="green">诗</td>
<td id= “P16” style="text-align:center" title="“tú“ diagram; chart, map, picture" class="green" >图</td>
<td id= “Q16” style="text-align:center" title="“xiǎn“ manifest, display; evident, clear" class="yellow" >显 </td>
</tr>
<tr>
<td id= “M17” style="text-align:center" title="“cí“ words, speech, expression, phrase" class="yellow" >辞</ td>
<td id= “N17” style="text-align:center" title="“lǐ“ reason, logic; manage" class="yellow" >理</td>
<td id= “O17” style="text-align:center" title="“xīng, xìng“ thrive, prosper, flourish" class="yellow" >兴</ td>
<td id= “P17” style="text-align:center" title="“yì“ right conduct, righteousness" class="yellow" >义</td>
<td id= “Q17” style="text-align:center" title="“yuàn“ hatred, enmity, resentment" class="yellow" >怨</td>
</tr>
</tbody>
</table>
<br>

这是 CSS:

type="text/css">                                                                                            
.table
{
border-collapse:collapse;
border-spacing:0;
}
.table td
{
font-family:Verdana,sans-serif;
font-size:19px;
padding:10px 5px;
border-style:solid;
border-width:1px;
overflow:hidden;
word-break:normal;
}
.table
.red {color:#fe0000}
.green {color:#32cb00}
.yellow {color:#ffc702}

我的 JAVAScript 查找表是:

var lookupTable = {
"端无终始诗":"The beginning of this poem starts at the end,",
"比平始璇情":"It begins peacefully like a smooth jade star",
"作苏心玑明":"Its creation revived my twisted heart",
"丽氏诗图显":"Clearly this star-chart poem is a classic",
"辞理兴义怨":"Knowledge thrives where good calls out evil",
"端比作丽辞":"The beginning of this work is like a great speech"};

(请注意,并非所有的点击组合都会产生英文翻译)。

我遇到的问题是:

  1. 创建一个事件监听器来检测点击并发送单元格中文文本框的内容
  2. 用查找表查找中文框中的文本
  3. 在英文翻译框中显示结果。

如有任何帮助,我们将不胜感激。尤其是写代码!

最佳答案

为结果添加几个元素:

<div id=output></div>
<div id=translation></div>

然后这段代码将处理点击并产生结果:

function processClick(event) {
var elem = $('#output');
elem.text(elem.text() + $(event.target).text());
$('#translation').text(lookupTable[elem.text()]);
}
$(document).on('click', 'td', processClick);

摆弄代码:
http://jsfiddle.net/6wjeuymj/1/

请注意,使用类名(示例:<div class=translator-puzzle> ... </div>)围绕表(和结果元素)的包装器将使您能够通过有效地使可重用组件依赖于在类而不是 id 上。

关于html - 用于表和查找表的 Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30906285/

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