IE Javascript样式显示不工作
我有两个div,其中一个的display属性默认为block,另一个为none。单击按钮时,会显示开关,因此一个隐藏,另一个显示。它可以在除IE之外的所有浏览器中工作。你知道为什么会发生这种情况吗?这与IE与innerHTML的问题有关吗?我将粘贴js和html JavaScript:IE Javascript样式显示不工作,javascript,html,css,Javascript,Html,Css,我有两个div,其中一个的display属性默认为block,另一个为none。单击按钮时,会显示开关,因此一个隐藏,另一个显示。它可以在除IE之外的所有浏览器中工作。你知道为什么会发生这种情况吗?这与IE与innerHTML的问题有关吗?我将粘贴js和html JavaScript: function show(id, elm){ var hide = document.getElementById(id); var show; var closeIcon = docu
function show(id, elm){
var hide = document.getElementById(id);
var show;
var closeIcon = document.getElementById("closeIcon");
if(id.substring(0, 3) != "set"){
elmName = "set"+id.substring(0, 1).toUpperCase() + id.substring(1, id.length);
if(id != "video") hide.style.display = "none";
show = document.getElementById(elmName);
show.style.display = "block";
$("#instruccionBox").hide();
$("#flechaEdit").hide();
}else{
elmName = id.substring(3, 4).toLowerCase() + id.substring(4, id.length);
hide.style.display = "none";
show = document.getElementById(elmName);
show.style.display = "block";
$("#instruccionBox").show();
$("#flechaEdit").show();
skipStep();
}
if(id.substring(0, 3) != "set" && id != "meta" && id != "fechaLimite"){
$('#closeIcon').show();
closeIcon.style.left = $(show).width() - 45 + "px";
closeIcon.style.top = "0px";
show.appendChild(closeIcon); //alert(show.id);
}
}
<div class="grid_4 proyectoDonaciones" id="meta">
<img src="images/edit-icon.png" alt="" class="editIcon" style="position:absolute; display:none" id="editMeta" onclick="show('meta')"/>
<h1 class="letter border1-pad2">META</h1>
<!--div class="triangulo_izq_claro"></div-->
<div>
<img src="images/cabezaIguana.png" alt="" width="70" class="editIcon" style="position:relative; left:12px;" onclick="show('meta')" id="cabezaMeta"/>
<div class="donacionesBarra">
<div style="margin:0 0 -60px 40%;"><h2 id="porcentajeMeta">0%<h2></div>
<table width="100%">
<tr height="45">
<td id="metaLeft" bgcolor="#a4c547" width="0%"></td>
<td id="metaRight" bgcolor="#FFFFFF" width="100%"></td>
<td><img src="images/colaIguana.png" alt="" width="70" style="position:absolute; left:250px;"/></td>
</tr>
<tr>
<td colspan="2"><span style="float:right;"><h3 style="color:#839e38;">$</h3></span></td>
</tr>
<tr>
<td colspan="2"><span style="float:right; font-size:15px;">of $<span id="metaText">9000</span> Goal</span></td>
</tr>
</table>
</div>
</div>
</div>
<div class="grid_4 proyectoDonaciones" style="margin-top:10px; display:none;" id="setMeta">
<h2 style="margin:10px;">Escriba la meta</h2>
<div style="margin:10px 25px 10px 10px;">
<input type="text" id="inputMeta" value="9000" style="width:100%;" class="pro_form2" / >
<br />
<center>
<input type="button" value="ACTUALIZAR" class="pro_btn pro_warning" onclick="show('setMeta', document.getElementById('closeIcon'))" />
</center>
</div>
</div>
HTML:
function show(id, elm){
var hide = document.getElementById(id);
var show;
var closeIcon = document.getElementById("closeIcon");
if(id.substring(0, 3) != "set"){
elmName = "set"+id.substring(0, 1).toUpperCase() + id.substring(1, id.length);
if(id != "video") hide.style.display = "none";
show = document.getElementById(elmName);
show.style.display = "block";
$("#instruccionBox").hide();
$("#flechaEdit").hide();
}else{
elmName = id.substring(3, 4).toLowerCase() + id.substring(4, id.length);
hide.style.display = "none";
show = document.getElementById(elmName);
show.style.display = "block";
$("#instruccionBox").show();
$("#flechaEdit").show();
skipStep();
}
if(id.substring(0, 3) != "set" && id != "meta" && id != "fechaLimite"){
$('#closeIcon').show();
closeIcon.style.left = $(show).width() - 45 + "px";
closeIcon.style.top = "0px";
show.appendChild(closeIcon); //alert(show.id);
}
}
<div class="grid_4 proyectoDonaciones" id="meta">
<img src="images/edit-icon.png" alt="" class="editIcon" style="position:absolute; display:none" id="editMeta" onclick="show('meta')"/>
<h1 class="letter border1-pad2">META</h1>
<!--div class="triangulo_izq_claro"></div-->
<div>
<img src="images/cabezaIguana.png" alt="" width="70" class="editIcon" style="position:relative; left:12px;" onclick="show('meta')" id="cabezaMeta"/>
<div class="donacionesBarra">
<div style="margin:0 0 -60px 40%;"><h2 id="porcentajeMeta">0%<h2></div>
<table width="100%">
<tr height="45">
<td id="metaLeft" bgcolor="#a4c547" width="0%"></td>
<td id="metaRight" bgcolor="#FFFFFF" width="100%"></td>
<td><img src="images/colaIguana.png" alt="" width="70" style="position:absolute; left:250px;"/></td>
</tr>
<tr>
<td colspan="2"><span style="float:right;"><h3 style="color:#839e38;">$</h3></span></td>
</tr>
<tr>
<td colspan="2"><span style="float:right; font-size:15px;">of $<span id="metaText">9000</span> Goal</span></td>
</tr>
</table>
</div>
</div>
</div>
<div class="grid_4 proyectoDonaciones" style="margin-top:10px; display:none;" id="setMeta">
<h2 style="margin:10px;">Escriba la meta</h2>
<div style="margin:10px 25px 10px 10px;">
<input type="text" id="inputMeta" value="9000" style="width:100%;" class="pro_form2" / >
<br />
<center>
<input type="button" value="ACTUALIZAR" class="pro_btn pro_warning" onclick="show('setMeta', document.getElementById('closeIcon'))" />
</center>
</div>
</div>
元
0%
$
达到9000美元的目标
梅塔描述
您的按钮正试图显示隐藏它的div
您需要以正确的div为目标,例如
<div id="firstDiv" style="border:1px solid red;">
first div here
<input type="button" value="show second" onclick="$('#secondDiv').show();$('#firstDiv').hide()" />
</div>
<div id="secondDiv" style="display: none; border:1px solid blue;">
second div here
<input type="button" value="show first" onclick="$('#firstDiv').show();$('#secondDiv').hide()" />
</div>
这里是第一组
这里是二等舱
如果已经加载了jQuery,为什么要使用纯js?每次都使用jQuery,因为它在几乎所有情况下都与浏览器兼容。我已经尝试过使用$(elm).show(),但它也不起作用。请尝试$('#'+elm).show()
。。应该工作是的,我做了,还是没有显示