You need to enable JavaScript to run this app. 使用JavaScript设置Stake HiLo投注金额时输入值自动重置失效求助
优惠活动
大模型
产品
解决方案
定价
更多

使用JavaScript设置Stake HiLo投注金额时输入值自动重置失效求助

Stake HiLo 页面自定义投注金额功能实现指南

赋值后被自动重置的核心原因

该类基于Vue/React等响应式框架开发的游戏页面,输入框的实际显示值与内部状态是双向绑定的。直接通过原生DOM的.value属性赋值,不会触发框架监听的输入事件,框架内部存储的投注金额仍为初始值,待框架执行定时状态同步、交互校验时,就会将手动写入DOM的覆盖值重置为内部存储的初始状态。

正确实现的核心逻辑

  • 等待页面游戏组件、投注输入框完全渲染完成后,再执行自定义元素的创建与绑定逻辑,避免出现元素定位失败
  • 给输入框赋值后,必须依次触发框架可识别的原生事件,将修改同步到框架内部状态,具体顺序为:
    1. 聚焦输入框,激活输入状态
    2. 清空输入框原有默认值
    3. 写入目标投注金额
    4. 触发带冒泡属性的input、change事件,让框架捕获到值的变更
    5. 触发失焦事件,完成平台侧的金额格式校验

可直接参考的优化实现代码

// 等待页面完全加载后执行逻辑
window.addEventListener('load', () => {
    // 按页面实际结构调整输入框选择器即可
    const betInputSelector = 'input[placeholder*="Bet Amount"], input[class*="bet-amount"]';
    let targetBetInput = null;

    // 轮询等待输入框渲染完成
    const inputCheckTimer = setInterval(() => {
        targetBetInput = document.querySelector(betInputSelector);
        if (!targetBetInput) return;
        clearInterval(inputCheckTimer);

        // 创建自定义基础投注设置按钮
        const btnSetBaseBet = document.createElement("button");
        btnSetBaseBet.textContent = "Set Base bet";
        btnSetBaseBet.id = "Base";
        // 按钮样式配置
        btnSetBaseBet.style.position = "absolute";
        btnSetBaseBet.style.backgroundColor = "white";
        btnSetBaseBet.style.padding = "10px 24px";
        btnSetBaseBet.style.bottom = "45px";
        btnSetBaseBet.style.width = "200px";
        btnSetBaseBet.style.fontSize = "17px";
        btnSetBaseBet.style.margin = "4px 2px";
        btnSetBaseBet.style.borderColor = "black";
        btnSetBaseBet.style.borderRadius = "4px";

        // 绑定按钮点击事件
        btnSetBaseBet.addEventListener("click", () => {
            const inputValue = prompt("请输入要设置的基础投注金额", "0.00000001");
            if (!inputValue || isNaN(Number(inputValue))) return;

            // 激活输入框状态
            targetBetInput.focus();
            // 清空原有值
            targetBetInput.value = "";
            // 写入目标投注金额
            targetBetInput.value = inputValue;
            // 触发冒泡事件同步到框架状态
            targetBetInput.dispatchEvent(new Event('input', { bubbles: true }));
            targetBetInput.dispatchEvent(new Event('change', { bubbles: true }));
            // 失焦触发金额校验
            targetBetInput.blur();
        })

        document.body.appendChild(btnSetBaseBet);
    }, 500)
})

常见问题排查

  • 如果输入框定位失败,可通过浏览器开发者工具直接选中投注金额输入框,复制对应的CSS选择器替换代码中的betInputSelector值
  • 如果赋值后仍被重置,检查事件触发时是否配置了bubbles: true——框架的事件监听器一般绑定在父级元素上,不冒泡的事件无法被框架捕获
  • 输入的金额格式需要匹配平台要求的精度,否则会因为格式校验不通过被自动重置

内容的提问来源于stack exchange,提问作者Dauersendung

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.16 23:24:00