cod*_*ris 4 javascript onclick show-hide
我想使用以下代码来显示隐藏的div onclick,但是当它显示时,我希望我用来触发它的图像消失.这是我到目前为止:
HTML:
<img src="Icons/note_add.png" onclick="show('comment')"/> <div id="comment" style="float:left;display:none;"><textarea name="textfield6" cols="30" rows="2" id="textfield4" class="text"></textarea> <a href="#" class="buttonintable">Submit</a></div>
Run Code Online (Sandbox Code Playgroud)
JS:
function show(target){
document.getElementById(target).style.display = 'block';
}
function hide(target){
document.getElementById(target).style.display = 'none';
}
Run Code Online (Sandbox Code Playgroud)
如何调整这个以隐藏触发它的元素?
Jimmy的答案会起作用,但为了让它显示回来(我假设你想要那样)你应该在图像标签上添加一个id ......以下内容应该有效.
<img id="clickMeId" src="Icons/note_add.png" onclick="show('comment')"/> <div id="comment" style="float:left;display:none;"><textarea name="textfield6" cols="30" rows="2" id="textfield4" class="text"></textarea> <a href="#" class="buttonintable">Submit</a></div>
function show(target){
document.getElementById(target).style.display = 'block';
document.getElementById("clickMeId").style.display = 'none';
}
function hide(target){
document.getElementById(target).style.display = 'none';
document.getElementById("clickMeId").style.display = 'block';
}
Run Code Online (Sandbox Code Playgroud)