2-1 百度输入法切换(三元运算符)

百度输入法切换,代码如下:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>输入法</title>
  <style>
    body,
    ul,
    li,
    button {
      margin: 0;
      padding: 0;
    }

    body {
      font: 12px/1.5 Tahoma;
    }

    ul {
      list-style-type: none;
    }

    button {
      cursor: pointer;
    }

    #outer {
      width: 70px;
      margin: 10px auto;
    }

    #ime {
      margin-top: 5px;
      border: 1px solid #9a99ff;
      display: none;
    }

    #ime li {
      width: 100%;
      /*定义基于包含块(父元素)宽度的百分比宽度*/
      line-height: 24px;
      display: inline-block;
      vertical-align: top;
    }

    #close {
      border-top: 1px solid #9a99ff;
    }

    #ime li a {
      color: #00c;
      padding: 0 5px;
      display: block;
      text-decoration: none;
    }

    #ime li a:hover {
      background: #d9e1f6;
    }
  </style>
  <script>
    window.onload = function () {
      var btn = document.getElementsByTagName("button")[0];
      var ime = document.getElementById("ime");
      var close = document.getElementById("close");
      var style = ime.style;
      btn.onclick = function () {
        style.display = style.display == "block" ? "none" : "block"
      } //三元运算符
      close.onclick = function () {
        style.display = "none"
      }
    }
  </script>
</head>

<body>
  <div id="outer">
    <button value="输入法">输入法</button>
    <ul id="ime">
      <li><a href="#">手写</a></li>
      <li><a href="#">拼音</a></li>
      <li id="close"><a href="#">关闭</a></li>
    </ul>
  </div>
</body>

</html>

三元运算符

语法

test ? expression1 : expression2

参数

test

任何 Boolean 表达式。

expression1

如果 test 为 true,则返回表达式。可能是逗号表达式。

expression2

如果 test 为 false,则返回表达式。可以使用逗号表达式链接多个表达式。

要查看英语原文,请勾选“英语”复选框。也可将鼠标指针移到文本上,在弹出窗口中显示英语原文。
翻译
英语

条件(三元)运算符 (?:) (JavaScript)

 

视情况返回以下两个表达式之一。

语法
 
 
 
 
test ? expression1 : expression2
参数
 
 
test

任何 Boolean 表达式。

expression1

如果 test 为 true,则返回表达式。可能是逗号表达式。

expression2

如果 test 为 false,则返回表达式。可以使用逗号表达式链接多个表达式。

转载于:https://www.cnblogs.com/Z-Imp/p/7287249.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值