小编16.*_*.uk的帖子

使用javascript将二进制转换为文本

如何使用javascript将二进制代码转换为文本?我已经将它转换为二进制文件,但有没有办法以相反的方式做到这一点?

这是我的代码:

function convertBinary() {
  var output = document.getElementById("outputBinary");
  var input = document.getElementById("inputBinary").value;
  output.value = "";
  for (i = 0; i < input.length; i++) {
    var e = input[i].charCodeAt(0);
    var s = "";
    do {
      var a = e % 2;
      e = (e - a) / 2;
      s = a + s;
    } while (e != 0);
    while (s.length < 8) {
      s = "0" + s;
    }
    output.value += s;
  }
}
Run Code Online (Sandbox Code Playgroud)
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<center>
  <div class="container">
    <span …
Run Code Online (Sandbox Code Playgroud)

html javascript

12
推荐指数
4
解决办法
6万
查看次数

如何执行不区分大小写的字符串比较?

我的网站上有一个文本框,用户可以输入命令.但问题是命令区分大小写.如何使命令不区分大小写?这是我的代码:

JavaScript的:

function showAlert() {

    var txtCtrl = document.getElementById("textbox1");

    var txtVal = txtCtrl.value;

    if (txtVal == '') {
        alert('Please fill in the text box. For a list of commands type "Help" into the text box.');
    }else if (txtVal == 'Start' || txtVal == 'start') {
        alert('Hello. What would you like me to do?');
    }else if (txtVal === 'Weather' || txtVal === 'weather') {
        window.location = "https://www.google.com/#q=weather";
    }else if (txtVal === 'Time' || txtVal === 'time') {
        alert('The current time according …
Run Code Online (Sandbox Code Playgroud)

javascript

4
推荐指数
2
解决办法
3万
查看次数

标签 统计

javascript ×2

html ×1