JavaScript函数以双引号返回div。喜欢 -
function Callback()
{
return "<div> <a href='javascript:void(0); > ENGLISH </a> </div>";
}
我想检查document.getElementById(&#39; language&#39;)。value == ENGLISH然后将颜色应用于ENGLISH字。那么如何将JavaScript变量与concatenate匹配。
在此先感谢。
答案 0 :(得分:1)
试试这个:
<div id='testElem'><a href='javascript:void(0)'>ENGLISH</a></div>
<script>
function Callback()
{
return "<div id='testElem'><a href='javascript:void(0)'>ENGLISH</a></div>";
}
function check()
{
if(document.getElementById('language').value == "ENGLISH")
{
console.log(document.getElementById("testElem").childNodes[0].style.color = 'red');
}
}
check();
</script>
答案 1 :(得分:1)
function Callback()
{
return "<div id='language'><a href='javascript:void(0);'> ENGLISH </a></div>";
}
var jslanguage=document.getElementById("language").textContent;
jslanguage=jslanguage.trim() ;// will get the text ENGLISH.
if(jslanguage== "ENGLISH"){
document.getElementById("language").style.color = "green";
}
答案 2 :(得分:0)
不确定这是否是您想要的:
<div id="language" value="ENGLISH">
</div>
var cookieValue = document.getElementById("language").getAttribute('value');
if(cookieValue == "ENGLISH"){
document.getElementById("language").style.color = "green";
}