简体   繁体   中英

Javascript unhide content

Should be simple and clear, but I dont get what is wrong here. Simple javascript show/hide content. Tryed both display - block/none and visibility - show/hidden. Not working.. It works if all divs visibility named npctext_X are set to visible. but i need them to be hidden, becouse this will be used in as dialogues...

<script type="text/javascript">

function npcfunkc(karodyt,senas){

var showit = 'npctext_'+karodyt;
var hideit = 'npctext_'+senas

//document.getElementById(showit).style.display='block';
//document.getElementById(hideit).style.display='none';

document.getElementById(showit).style.visibility = 'show';
document.getElementById(hideit).style.visibility = 'hidden';
}
</script>


<div class='npctalk'>

<div id='npctext_1' style='visibility:visible;'>text 1 text 1 text 1 <br /><br />
    <button onclick='npcfunkc(2,1)'>show 2 [hide 1]
    </button><br />
    <button onclick='npcfunkc(3,1)'>show 3 [hide 1]
    </button><br />
</div>

<div id='npctext_2' style='visibility:hidden;'>text 2 text 2 text 2 <br /><br />
    <button onclick='npcfunkc(1,2)'>show 1, [hide 2]
    </button><br />
    <button onclick='npcfunkc(3,2)'>show 3, [hide 2]
    </button><br />
</div>

<div id='npctext_3' style='visibility:hidden;'>text 3 text 3 text 3 <br /><br />
    <button onclick='npcfunkc(2,3)'>show 2, [hide 3]
    </button><br />
    <button onclick='npcfunkc(1,3)'>show 1, [hide 3]
    </button><br />
</div>

</div>

As a best-practice and potential solution to your problem, you should use CSS classes and add or remove those classes from your objects.

This Tutorial may help you.

mYou are sending integers to your function. Try wrapping them with quotes like this to convert them to string....

npcfunkc("2", "1")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM