cptJS密码输入效果没有带“*****”,直接展示出密码了,怎么可以显示成***

image.png

FineReport 帆软用户VQHkSnUE2a 发布于 2025-7-30 17:11
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
0
runnerLv7资深互助
发布于2025-7-30 17:19

function hideInput(input) {

  // 替换所有字符为星号

  return input.toString().replace(/./g, '*');

}

// 使用示例

console.log(hideInput("abc123")); // 输出: ******

console.log(hideInput(123456));  // 输出: ******

用js就可以设置,把输入的变为 *

  • 帆软用户VQHkSnUE2a 帆软用户VQHkSnUE2a(提问者) const password = () => {
    var i = 0; // 改变初始值为0以提供3次机会
    var passwd;
    while (i < 3) {
    passwd = prompt("请输入密码:");
    if (passwd == "--+") { // 假设密码预先设置为123
    break;
    }
    i++;
    alert("密码错误!请重新输入:\n你还有" + (3 - i) + "次机会。"); // 更新剩余机会的计算
    }
    if (passwd != "--+" && i == 3) {
    alert("连续密码错误,即将跳转至其他页面");
    location.href = "http://10.83.1.251:8080/"; // 直接跳转而不尝试关闭页面
    }
    };
    password();
    这是我的原JS,可以帮我在这段上面该一下吗?
    2025-07-30 17:27 
最佳回答
0
农夫三拳1Lv6中级互助
发布于2025-7-30 17:25(编辑于 2025-7-30 17:31)

这样写试一下

FR.Msg.advancedPrompt("输入", "请输入您的爱好:", "", { type: 'password' }, function(result)

image.png

--------------------------------------------------------------------------

const password = () => {

  let i = 0; // 尝试次数计数器

  let passwd; // 存储密码

  

  function showPasswordDialog(remainingAttempts) {

    // 创建密码输入弹窗

    const dialog = document.createElement('div');

    dialog.style.cssText = `

      position: fixed;

      top: 50%;

      left: 50%;

      transform: translate(-50%, -50%);

      background: white;

      padding: 20px;

      border: 1px solid #ccc;

      border-radius: 5px;

      box-shadow: 0 0 10px rgba(0,0,0,0.2);

      z-index: 9999;

    `;

    

    // 创建密码输入框(type="password"会显示为***)

    const input = document.createElement('input');

    input.type = 'password'; // 关键修改:设置为密码类型

    input.placeholder = '请输入密码';

    input.style.cssText = `

      padding: 8px;

      margin: 10px 0;

      width: 200px;

      display: block;

    `;

    

    // 提示信息

    const message = document.createElement('p');

    message.textContent = `您还有 ${remainingAttempts} 次尝试机会`;

    message.style.color = 'red';

    

    // 创建按钮容器

    const buttonContainer = document.createElement('div');

    buttonContainer.style.textAlign = 'right';

    buttonContainer.style.marginTop = '10px';

    

    // 确定按钮

    const confirmBtn = document.createElement('button');

    confirmBtn.textContent = '确定';

    confirmBtn.onclick = () => {

      const inputValue = input.value;

      if (!inputValue) {

        alert('密码不能为空!');

        return;

      }

      processPassword(inputValue);

      document.body.removeChild(dialog);

    };

    

    // 取消按钮

    const cancelBtn = document.createElement('button');

    cancelBtn.textContent = '取消';

    cancelBtn.style.marginLeft = '10px';

    cancelBtn.onclick = () => {

      document.body.removeChild(dialog);

      // 取消操作后的处理

      alert('连续密码错误,即将跳转至其他页面');

      location.href = "http://10.83.1.251:8080/";

    };

    

    // 组装元素

    dialog.appendChild(document.createTextNode('请输入密码:'));

    dialog.appendChild(document.createElement('br'));

    dialog.appendChild(input);

    dialog.appendChild(message);

    buttonContainer.appendChild(confirmBtn);

    buttonContainer.appendChild(cancelBtn);

    dialog.appendChild(buttonContainer);

    

    // 添加到DOM

    document.body.appendChild(dialog);

    

    // 自动聚焦到输入框

    input.focus();

  }

  

  function processPassword(inputValue) {

    if (inputValue === "--+") { // 假设密码是123

      // 密码正确

      return;

    }

    

    i++;

    if (i < 3) {

      alert("密码错误!请重新输入:\n你还有" + (3 - i) + "次机会。");

      showPasswordDialog(3 - i);

    } else {

      alert("连续密码错误,即将跳转至其他页面");

      location.href = "http://10.83.1.251:8080/";

    }

  }

  

  // 启动密码验证流程

  showPasswordDialog(3);

};

password();

  • 帆软用户VQHkSnUE2a 帆软用户VQHkSnUE2a(提问者) 目的是达到了,不过就是JS太多了。可以删减掉密码输入框在屏幕中间的那段JS。
    2025-07-30 17:36 
  • 3关注人数
  • 58浏览人数
  • 最后回答于:2025-7-30 17:31
    请选择关闭问题的原因
    确定 取消
    返回顶部