我为每个 JavaScript 添加了一个带有文本的元素。有了这个代码:
$(document).ready(function () {
if ($('welcome_page').length) {
$('#my_element').after('<tr><td><td><td id="welcome_message">Welcome to my page</td></td></td</tr>');
}
});
我需要能够根据页面中设置的语言更改文本>欢迎来到我的页面
<select id="languages" onchange="submit();">
<option value="1" selected="">English</option>
<option value="2">Spanish</option>
<option value="3">French</option>
</select>
我已经尝试过这个,但它没有解决问题:
function langChoice(sel){
var langChange = document.getElementById('languages');
var langOption = document.getElementById('welcome_message');
if ( sel.options[sel.selectedIndex].value == "1" ) {
langOption.innerHTML = "Enter price per month";
}
else if ( sel.options[sel.selectedIndex].value == "2" ) {
langOption.innerHTML = "Enter price per week";
}
else if ( sel.options[sel.selectedIndex].value == "3" ) {
langOption.innerHTML = "Enter price per day";
}
else if ( sel.options[sel.selectedIndex].value == "4" ) {
langOption.innerHTML = "Enter for sale hour";
}
}
我猜...
访问这个JsFiddle http://jsfiddle.net/L93qwey4/
HTML:
<div id="greet"></div>
<select id="languages">
<option value="en" >English</option>
<option value="es" selected>Spanish</option>
<option value="fr">French</option>
</select>
JS:
var welcome = {
en:"English",
es:"Espanol",
fr:"Francais"
}
$(document).ready(function () {
$('#greet').html(welcome[$('#languages').val()]);
});
$('#languages').change(function () {
$('#greet').html(welcome[$('#languages').val()]);
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)