问题
I am building an offline multi-page mobile application on Dreamweaver, and I am trying to make it so that the application can detect only certain <h1>
s and translate them to the locale language the users phone is set to, but I do not know how. below, I want the top <h1>
to be translated to the users locale language, while leaving the bottom <h1>
in English.
//html
<h1 class="TopText" id="HouseT">Apartment</h1>
<img src"~"/>
<h1 class="BotText" id="HouseB">Apartment</h1>
回答1:
Using jQuery you could write a selector, that matches the first h1 element, but not the second. For example:
'h1.TopText'
(select h1 elements having ToText class attribute) or 'h1#HouseT'
(selecting h1 elements having HouseT as id) and then go on and manipulate it's contents.
Here is a working example:
$('h1.TopText').html('some other text');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1 class="TopText" id="HouseT">Apartment</h1>
<img src"http://placehold.it/100x100"/>
<h1 class="BotText" id="HouseB">Apartment</h1>
来源:https://stackoverflow.com/questions/38416738/locale-language-detection-and-translation