小编Dio*_*nes的帖子

通过javascript更改div id

每次按下提交时,我都创建了一个简单的页面来更改div id.我的问题是,这从div_top1 - > div_top2更改,但第二次按下按钮,它停止更改:(

<!DOCTYPE html>
<html>
    <head>
        <script>   
            function changediv()
            {                                                    
                document.getElementById("div_top1").innerHTML=Date();          
                document.getElementById("div_top1").setAttribute("id", "div_top2");
                document.getElementById("div_top2").innerHTML="teste";            
                document.getElementById("div_top2").setAttribute("id", "div_top1");
            }
        </script>

        <style>
            .top {               
                background-color: navy;    
                color: white;
                padding: 10px 10px 10px 10px;   
                margin: 5px 5px 5px 5px;                                 
            }

            .down {             
                background-color: aqua;
                padding: 10px 10px 10px 10px;
                margin: 5px 5px 5px 5px;        
            }         
        </style>

    </head>
    <body>
        <div id="div_top1" class="top">This is a paragraph.</div>
        <div class="down"><button type="button" onclick="changediv()">Display Date</button></div>
    </body>
</html> 
Run Code Online (Sandbox Code Playgroud)

html javascript

7
推荐指数
1
解决办法
5万
查看次数

在php函数中返回一个值

Hy,我有这个代码例如:

function generateRandStr($length){
      $randstr = "";
      for($i=0; $i<$length; $i++){
         $randnum = mt_rand(0,61);
         if($randnum < 10){
            $randstr .= chr($randnum+48);
         }else if($randnum < 36){
            $randstr .= chr($randnum+55);
         }else{
            $randstr .= chr($randnum+61);
         }
      }
      return $randstr;
   } 
Run Code Online (Sandbox Code Playgroud)

但当它试图在主要使用时:

    generateRandStr(10); 
    echo $irandstr;
Run Code Online (Sandbox Code Playgroud)

我不做什么?:(

php random

0
推荐指数
1
解决办法
94
查看次数

标签 统计

html ×1

javascript ×1

php ×1

random ×1