Javascript - 在新窗口中的 toUpperCase

标签 javascript

这就是我想要的代码。当您写入任何单词时,它会使用 onkeyup 自动更改为大写。此外,当用户单击新窗口时,大写字母将显示在新窗口中。我只能做第一部分。我该怎么做呢? https://jsfiddle.net/p3zea7Lu/11/

<body>
  <div>
    <form>
      <br /><br /> Type in your text: <br />
      <p>
        <input type="text" size="30" id="input" onkeyup="convertToUppercase()" />
      </p>
      <p id="output"></p>
    </form>

    <br />
    <button onclick="myFunction()">Open new window</button>

  </div>
  <script>
    function convertToUppercase() {
      document.getElementById('output').innerHTML = document.getElementById('input').value.toUpperCase();
    }

    function myFunction() {
      var myWindow = window.open("", "MsgWindow", "width=200,height=100");
      myWindow.document.write("The word is:" + input);
    }
  </script>
</body>

最佳答案

将您的myFunction更改为以下内容。

function myFunction(val) {
        var myWindow = window.open("", "MsgWindow", "width=200,height=100");
        myWindow.document.write("The word is:" + document.getElementById('output').innerHTML);
    }

关于Javascript - 在新窗口中的 toUpperCase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57783791/

相关文章:

javascript - 如何在 Javascript 中创建 Scramble 函数

javascript - 尝试绘制从鼠标位置的工具栏中选择的形状-HTML5 CANVAS

javascript - 扩展 Bootstrap Popover 插件

c# - 商店通用应用程序上的 WebClient

javascript - 自调用函数的替代语法?

javascript - Firebug - 搜索嵌套的 dom 节点

javascript - 从单独的网络访问 Node.js 服务器

javascript - 我可以用 ESlint 强调 let 作用域问题吗?

javascript - 使用谷歌地图感知地理位置

javascript - Jquery 中的按键事件