雪球调仓时输入小数

雪球调仓时可以输入小数

< Feedback on 雪球调仓时输入小数

Review: Good - script works

§
Posted: 2024-05-10
Edited: 2024-05-10

6

chatgpt的注释


(function() {
    // 定义失焦处理函数
    function blurHandler(event) {
        // 设置初始现金金额为10000
        let cash = 10000;
        // 获取所有股票行
        const trs = $('#cube-stock tr.stock');
        // 获取行数
        const length = trs.length;
        // 遍历所有股票行
        for (let i = 0; i < length; i++) {
            const tr = $(trs[i]);
            // 获取当前行的输入框中的权重值
            const weight = Number(tr.find('input.weight').val().replace('%', ''));
            // 查找对应股票数据
            const data = SNB.cubeData.find(n => n.stock_id == tr.attr('data-id'));
            // 如果找到对应股票数据且权重值发生了变化
            if (data && data.weight != weight) {
                // 标记股票数据已经被修改
                data.proactive = true;
                // 更新股票权重
                data.weight = weight;
            }
            // 更新剩余现金金额
            cash -= weight * 100;
        }
        // 将现金金额转为两位小数
        cash = +(cash / 100).toFixed(2);
        // 更新页面上的现金金额输入框和显示值
        $('.cash .stock-weight input').val(cash);
        $('.cash .stock-weight span.weight').text(cash + '%');
        // 更新全局变量中的现金权重
        SNB.cashWeight = cash;
        // 阻止事件冒泡
        event.stopPropagation();
        return false;
    }

    // 每50毫秒重新绑定失焦事件,确保失焦事件一直生效
    setInterval(function(){
        $('input.weight').off('blur').blur(blurHandler);
    }, 50);
})();

Post reply

Sign in to post a reply.