当前位置:   article > 正文

JS实战之单词背诵的实现_背单词程序javascript代码

背单词程序javascript代码

代码展示:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title></title>
  6. <style>
  7. *{
  8. margin: 0;
  9. padding: 0;
  10. }
  11. .box{
  12. width: 100%;
  13. height: 930px;
  14. background-color: #FCFCE5;
  15. }
  16. .wrapper{
  17. width: 1920px;
  18. height: 100%;
  19. position: relative;
  20. font-size: 16px;
  21. /* border: 1px solid black; */
  22. }
  23. .content{
  24. display: inline-block;
  25. width: 100px;
  26. height: 100px;
  27. border-radius: 20px;
  28. overflow: hidden;
  29. margin-top: 20px;
  30. margin-right: 20px;
  31. border: 1px solid black;
  32. }
  33. .content p{
  34. width: 100px;
  35. height: 50px;
  36. text-align: center;
  37. line-height: 50px;
  38. }
  39. .content p:first-of-type{
  40. border-bottom: 1px dashed red;
  41. }
  42. .wu{
  43. display: none;
  44. }
  45. .btn{
  46. width: 180px;
  47. height: 30px;
  48. line-height: 20px;
  49. text-align: center;
  50. padding: 10px;
  51. border-radius: 10px;
  52. position: absolute;
  53. bottom: 0;
  54. left: 50%;
  55. margin-left: -90px;
  56. background-color: orange;
  57. border: 1px solid black;
  58. }
  59. .btn select{
  60. font-size: 16px;
  61. }
  62. .btn button{
  63. font-size: 16px;
  64. }
  65. </style>
  66. </head>
  67. <body>
  68. <div class="box">
  69. <div class="wrapper">
  70. <!-- <div class="content">
  71. <p>单词</p>
  72. <p class="wu">单词</p>
  73. <p>翻译</p>
  74. </div> -->
  75. <div class="btn">
  76. <select name="opt" id="">
  77. <option value="1">中文转英文</option>
  78. <option value="2">英文转中文</option>
  79. </select>
  80. <button>下一个</button>
  81. </div>
  82. </div>
  83. </div>
  84. <script>
  85. var data=[
  86. {
  87. "en":"device",
  88. "cn":"设备"
  89. },
  90. {
  91. "en":"width",
  92. "cn":"宽度"
  93. },
  94. {
  95. "en":"height",
  96. "cn":"高度"
  97. },
  98. {
  99. "en":"init",
  100. "cn":"初始"
  101. },
  102. {
  103. "en":"content",
  104. "cn":"内容"
  105. },
  106. {
  107. "en":"container",
  108. "cn":"容器"
  109. },
  110. {
  111. "en":"charset",
  112. "cn":"编码"
  113. },
  114. {
  115. "en":"doc",
  116. "cn":"文档"
  117. },
  118. {
  119. "en":"type",
  120. "cn":"类型"
  121. },
  122. {
  123. "en":"public",
  124. "cn":"公共的"
  125. },
  126. {
  127. "en":"config",
  128. "cn":"配置"
  129. },
  130. {
  131. "en":"src",
  132. "cn":"源文件"
  133. },
  134. {
  135. "en":"background",
  136. "cn":"背景"
  137. },
  138. {
  139. "en":"front",
  140. "cn":"前"
  141. },
  142. {
  143. "en":"elements",
  144. "cn":"元素"
  145. },
  146. {
  147. "en":"content",
  148. "cn":"内容"
  149. },
  150. {
  151. "en":"console",
  152. "cn":"控制台"
  153. },
  154. {
  155. "en":"source",
  156. "cn":"源代码"
  157. },
  158. {
  159. "en":"network",
  160. "cn":"网络"
  161. },
  162. {
  163. "en":"audio",
  164. "cn":"声音"
  165. },
  166. {
  167. "en":"controls",
  168. "cn":"控件"
  169. },
  170. {
  171. "en":"video",
  172. "cn":"视频"
  173. },
  174. {
  175. "en":"autoplay",
  176. "cn":"自动播放"
  177. },
  178. {
  179. "en":"filter",
  180. "cn":"过滤"
  181. },
  182. {
  183. "en":"order",
  184. "cn":"排序"
  185. },
  186. {
  187. "en":"list",
  188. "cn":"列表"
  189. },
  190. {
  191. "en":"script",
  192. "cn":"脚本"
  193. },
  194. {
  195. "en":"class",
  196. "cn":"类名"
  197. },
  198. {
  199. "en":"app",
  200. "cn":"应用"
  201. },
  202. {
  203. "en":"top",
  204. "cn":"顶部"
  205. },
  206. {
  207. "en":"bottom",
  208. "cn":"底部"
  209. },
  210. {
  211. "en":"left",
  212. "cn":"左侧"
  213. },
  214. {
  215. "en":"right",
  216. "cn":"右侧"
  217. },
  218. {
  219. "en":"middle",
  220. "cn":"中间"
  221. },
  222. {
  223. "en":"use",
  224. "cn":"使用"
  225. },
  226. {
  227. "en":"row",
  228. "cn":"行"
  229. },
  230. {
  231. "en":"column",
  232. "cn":"列"
  233. },
  234. {
  235. "en":"border",
  236. "cn":"边框"
  237. },
  238. {
  239. "en":"align",
  240. "cn":"对齐"
  241. },
  242. {
  243. "en":"padding",
  244. "cn":"内补"
  245. },
  246. {
  247. "en":"target",
  248. "cn":"目标"
  249. },
  250. {
  251. "en":"table",
  252. "cn":"表格"
  253. },
  254. {
  255. "en":"form",
  256. "cn":"表单"
  257. },
  258. {
  259. "en":"submit",
  260. "cn":"提交"
  261. },
  262. {
  263. "en":"input",
  264. "cn":"输入"
  265. },
  266. {
  267. "en":"label",
  268. "cn":"提示文字"
  269. },
  270. {
  271. "en":"data",
  272. "cn":"数据"
  273. },
  274. {
  275. "en":"date",
  276. "cn":"日期"
  277. },
  278. {
  279. "en":"get",
  280. "cn":"获取"
  281. },
  282. {
  283. "en":"post",
  284. "cn":"创建"
  285. },
  286. {
  287. "en":"method",
  288. "cn":"方法"
  289. },
  290. {
  291. "en":"action",
  292. "cn":"服务地址"
  293. },
  294. {
  295. "en":"set",
  296. "cn":"集合"
  297. },
  298. {
  299. "en":"link",
  300. "cn":"链接"
  301. },
  302. {
  303. "en":"tag",
  304. "cn":"标签"
  305. },
  306. {
  307. "en":"attribute",
  308. "cn":"属性"
  309. },
  310. {
  311. "en":"value",
  312. "cn":"值"
  313. },
  314. {
  315. "en":"hover",
  316. "cn":"划入"
  317. },
  318. {
  319. "en":"focus",
  320. "cn":"聚焦"
  321. },
  322. {
  323. "en":"parent",
  324. "cn":"父"
  325. },
  326. {
  327. "en":"child",
  328. "cn":"子"
  329. },
  330. {
  331. "en":"empty",
  332. "cn":"空"
  333. },
  334. {
  335. "en":"select",
  336. "cn":"选择"
  337. },
  338. {
  339. "en":"font",
  340. "cn":"字体"
  341. },
  342. {
  343. "en":"text",
  344. "cn":"文本"
  345. },
  346. {
  347. "en":"shadow",
  348. "cn":"阴影"
  349. },
  350. {
  351. "en":"box",
  352. "cn":"盒子"
  353. },
  354. {
  355. "en":"repeat",
  356. "cn":"重复"
  357. },
  358. {
  359. "en":"position",
  360. "cn":"位置"
  361. },
  362. {
  363. "en":"margin",
  364. "cn":"输入"
  365. },
  366. {
  367. "en":"input",
  368. "cn":"外边距"
  369. },
  370. {
  371. "en":"border",
  372. "cn":"边框"
  373. },
  374. {
  375. "en":"padding",
  376. "cn":"内补"
  377. },
  378. {
  379. "en":"size",
  380. "cn":"尺寸"
  381. },
  382. {
  383. "en":"transform",
  384. "cn":"变换"
  385. },
  386. {
  387. "en":"translate",
  388. "cn":"移动"
  389. },
  390. {
  391. "en":"rotate",
  392. "cn":"旋转"
  393. },
  394. {
  395. "en":"from",
  396. "cn":"从哪里"
  397. },
  398. {
  399. "en":"to",
  400. "cn":"到哪里"
  401. },
  402. {
  403. "en":"transition",
  404. "cn":"渐变"
  405. },
  406. {
  407. "en":"origin",
  408. "cn":"起点"
  409. },
  410. {
  411. "en":"static",
  412. "cn":"静态"
  413. },
  414. {
  415. "en":"relative",
  416. "cn":"相对"
  417. },
  418. {
  419. "en":"absolute",
  420. "cn":"绝对"
  421. },
  422. {
  423. "en":"scale",
  424. "cn":"缩放"
  425. },
  426. {
  427. "en":"sticky",
  428. "cn":"粘性"
  429. },
  430. {
  431. "en":"fixed",
  432. "cn":"固定"
  433. },
  434. {
  435. "en":"inline",
  436. "cn":"行内"
  437. },
  438. {
  439. "en":"flex",
  440. "cn":"弹性容器"
  441. },
  442. {
  443. "en":"direction",
  444. "cn":"方向"
  445. },
  446. {
  447. "en":"item",
  448. "cn":"项目"
  449. },
  450. {
  451. "en":"grow",
  452. "cn":"增长"
  453. },
  454. {
  455. "en":"shrink",
  456. "cn":"压缩"
  457. },
  458. {
  459. "en":"start",
  460. "cn":"起点"
  461. },
  462. {
  463. "en":"end",
  464. "cn":"终点"
  465. },
  466. {
  467. "en":"icon",
  468. "cn":"图标"
  469. },
  470. {
  471. "en":"float",
  472. "cn":"浮动"
  473. },
  474. {
  475. "en":"local",
  476. "cn":"本地"
  477. },
  478. {
  479. "en":"global",
  480. "cn":"全局"
  481. }
  482. ]
  483. var wrapper=document.querySelector(".wrapper");
  484. var ps=document.querySelectorAll("p");
  485. var select=document.querySelector("select")
  486. var count=0;
  487. var btn=document.querySelector("button");
  488. console.log(select.value);
  489. /* 创建新的单词框 */
  490. btn.onclick=function(){
  491. if(count>=data.length){
  492. alert("恭喜你,你已经完成任务!!,请继续努力")
  493. location.reload();
  494. }else{
  495. var content=document.createElement("div");
  496. var p1=document.createElement("p");//存放单词
  497. var p2=document.createElement("p");//存放答案
  498. var p3=document.createElement("p");//存放翻译
  499. p1.innerText=data[count].cn;
  500. p2.innerText="翻译";
  501. p3.innerText=data[count].en;
  502. content.classList.add("content");
  503. wrapper.append(content);
  504. if(select.value==2){//如果是英文转中文则用这个
  505. content.append(p3);
  506. content.append(p2);
  507. content.append(p1);
  508. }else{//如果是中文转英文则用这个
  509. content.append(p1);
  510. content.append(p2);
  511. content.append(p3);
  512. }
  513. p2.onclick=function(){
  514. p2.classList.add("wu")//"翻译"消失
  515. }
  516. }
  517. count++;
  518. }
  519. </script>
  520. </body>
  521. </html>

结果展示:

初始界面

 可以在下面进行中英文转换

 点击下一个就会出来单词

 你可以点击翻译去查看单词的真正意思

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/爱喝兽奶帝天荒/article/detail/956095
推荐阅读
相关标签
  

闽ICP备14008679号