How can I convert language of a div?(如何转换 div 的语言?)
问题描述
我最近在一个项目中工作.在那里我需要通过按钮单击事件将语言从英语转换为日语.文本位于 div 中.像这样:
I am recently working in a project. There I need to convert language from English to Japanese by button click event. The text is in a div. Like this:
"<div id="sampletext"> here is the text </div>"
"<div id="normaltext"> here is the text </div>"
文本来自数据库.如何轻松转换此文本?
The text is come from database. How can I convert this text easily?
推荐答案
假设你的数据库中有英文版和日文版,你可以做两件事:
Assuming that you have both the English and the Japanese version in the database, you can do two things:
- 使用 AJAX 从数据库中加载正确的文本并替换 div 的内容.互联网上有大量关于 AJAX 内容替换的教程.
- 将两种语言都放在网站上,并使用 CSS display:none 隐藏其中一种.然后在单击按钮时使用一些 JavaScript 隐藏/显示正确的 div.
第一个在技术上更复杂,但可以保持页面较小.第二个很容易做到,但是你的页面比较大,因为你需要发送两种语言.
The first is technically more complex but keeps your page size small. The second one is very easy to do, but your page size is larger because you need to send both languages.
如果 div 很小,页面上只有一两个,我推荐第二个,CSS 技术.如果 div 很大(即一篇完整的文章)或有很多,则使用第一种方法.
If the div is small and there is only one or two of these on the page, I recommend number two, the CSS technique. If the div is large (i.e. a complete article) or there are many of them then use the first method.
这篇关于如何转换 div 的语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何转换 div 的语言?


- PHP Count 布尔数组中真值的数量 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- Laravel 仓库 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01