javascript - Display a sessionStorage item - Stack Overflow

I want to display the field player but i can't:<body><header><h1>My memory Game&

I want to display the field player but i can't:

<body>

       <header>
    <h1>My memory Game</h1>
</header>

<div id="timer">
    Player Name: 
    <span id="player-name">

               <script type='text/javascript'>

                sessionStorage.getItem('player');

                //alert("Your name is: " + sessionStorage.getItem('player'));    

               </script>    
    </span>
</div>

When i test it by using javascript alert everything work : the player name is desplayed without a problem Any idea please

I want to display the field player but i can't:

<body>

       <header>
    <h1>My memory Game</h1>
</header>

<div id="timer">
    Player Name: 
    <span id="player-name">

               <script type='text/javascript'>

                sessionStorage.getItem('player');

                //alert("Your name is: " + sessionStorage.getItem('player'));    

               </script>    
    </span>
</div>

When i test it by using javascript alert everything work : the player name is desplayed without a problem Any idea please

Share asked Apr 22, 2012 at 11:14 Amira ManaiAmira Manai 2,5998 gold badges42 silver badges60 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

sessionStorage.getItem('player') returns a string. you should do something with it. like display in alert. - which is working according to your details...

once you have the value you can put it in element

ie:

myelement.inneHtml=sessionStorage.getItem('player')

Use this:

document.getElementById('player-name').innerHTML = 
     sessionStorage.getItem('player');

Fixed code:

<body>
    <header>
        <h1>My memory Game</h1>
    </header>
    <div id="timer">
        Player Name: 
        <span id="player-name">
        </span>
    </div>
    <script type='text/javascript'>
        document.getElementById('player-name').innerHTML = sessionStorage.getItem('player');
    </script>    

You should do some javascript tutorials. ​

this will write it into your span you should place the script tag below the span (i do not know what happens if you overwrite it while execution, might work as well)

document.getElementById("player-name").innerHTML = sessionStorage.getItem('player');

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742291290a4416236.html

相关推荐

  • javascript - Display a sessionStorage item - Stack Overflow

    I want to display the field player but i can't:<body><header><h1>My memory Game&

    18小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信