美文网首页
练手-随机获取名言

练手-随机获取名言

作者: 西西西瓜sama | 来源:发表于2018-03-22 18:00 被阅读12次
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Random Quote Machine</title>
    <style>
        body{
            background-color: red;

        }
        .main{
            background-color: white;
            max-width: 600px;
            min-height: 100px;
            margin: 0 auto;
            position: relative;
        }
        .content{
            color: red;
            font-size: 30px;
            text-align: center;
            position: relative;
            top: 20px;
        }
        .writer{
            color: red;
            text-align: right;
            margin-right: 20px;
            /*position: relative;*/
            /*right: 20px;*/
        }
        .btn{
            background-color: red;
            color: white;
            width: 120px;
            height: 40px;
            font-size: 15px;
            margin-left: 460px;
            margin-bottom: 20px;
            /*position: absolute;*/
            /*right: 20px;*/
            /*bottom: 20px;*/

        }
    </style>

    <script type="text/javascript">

        window.onload = function () {

            document.getElementsByClassName("content")[0].innerHTML = "I can fly";
            document.getElementsByClassName("writer")[0].innerHTML = "LPD";

            changeContent();

        }

        var xmlhttp;

        function netWork(url,cfunc) {

            xmlhttp = new XMLHttpRequest();
            xmlhttp.onreadystatechange = cfunc;
            xmlhttp.open("GET",url,true);
            xmlhttp.setRequestHeader('X-Mashape-Key','OivH71yd3tmshl9YKzFH7BTzBVRQp1RaKLajsnafgL2aPsfP9V');
            xmlhttp.send();

        }

        function changeContent() {

            netWork("https://andruxnet-random-famous-quotes.p.mashape.com/cat=",function () {

                if (xmlhttp.readyState == 4 && xmlhttp.status == 200){

                    var result = JSON.parse(xmlhttp.responseText);

                    var main = document.getElementsByClassName("main")[0];

//                    if (result.quote.length > 45){
//
//                        main.style.minHeight = 400 + "px";
//
//
//                    }else {
//
//                        main.style.minHeight = 200 + "px";
//                    }

                    //改变颜色
                    var color = "#" + randomNum();

                    document.getElementsByClassName("content")[0].style.color = color;
                    document.getElementsByClassName("writer")[0].style.color = color;
                    document.getElementsByClassName("btn")[0].style.backgroundColor = color;
                    document.getElementsByTagName("body")[0].style.backgroundColor = color;


                    document.getElementsByClassName("content")[0].innerHTML = result.quote;
                    document.getElementsByClassName("writer")[0].innerHTML = result.author;

                }

            })

        }

        //产生随机数
        function randomNum() {

            var rnd = "";
            for(var i=0;i<6;i++){
                rnd += Math.floor(Math.random()*10);
            }

            return rnd;

        }

        function goto() {
            window.location.href = 'home_vue.html';
        }

    </script>

</head>
<body>
<div class="main">
    <p class="content"></p>
    <p class="writer"></p>
    <button class="btn" type="button" onclick="changeContent()">New Quote</button>
</div>
</body>
</html>

相关文章

  • 练手-随机获取名言

  • 获取随机数

    获取随机数的几个小栗子 1.颜色随机 2.获取两数之间的随机数 指定值中获取随机数 4.获取随机的ip地址(0-255)

  • swift 随机数

    获取 Int 类型的随机数 调用方法如下: 获取Float 类型的随机数 调用方法如下: 获取CGFloat 类型...

  • iOS彩票类排列组合算法

    1. 从一个范围内获取一组不重复的随机数,返回这个数组: 头文件: /*获取随机数@param count获取随机...

  • [MySQL]随机数

    获取[0, 1)的随机数 select rand() 获取[i, j)的随机数 select floor(i + ...

  • 随机获取图片

    随机获取300X300图片 https://source.unsplash.com/300x300 随机获取320...

  • rand.Seed(time.Now().UnixNano())

    rand.Int获取随机数,不加随机种子,每次遍历获取都是重复的一些随机数据 rand.Seed(time.Now...

  • 常用负载均衡算法

    1.随机 获取服务列表大小范围内的随机数,将随机数作为列表索引, 从服务列表中获取服务提供者。 2.加权随机 按照...

  • php生成N位的随机字符串

    利用随机数获取字符池中的随机位 一 二

  • 获取随机RGB

    int R = (arc4random() % 256) ; int G = (arc4random() ...

网友评论

      本文标题:练手-随机获取名言

      本文链接:https://www.haomeiwen.com/subject/wjfzqftx.html