RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题

全部问题

Martin Hope
Dina
Asked: 2025-04-20 19:03:00 +0000 UTC

输入改变后如何更改 html 块中的数据?

  • 5

几个输入字段分别包含从 0 到 4 的数据。这些输入中总共输入了多少个单位,div 中总数的百分比被添加到这个div id="price1"输入中,input id="price"

假设价格是 500 卢布

在输入框中输入 5

一个单位的投入=2%

500+10% 或 500x1.1

结果四舍五入到十分位

// Убавляем кол-во по клику
$('.quantity_inner .bt_minus').click(function() {
    let $input = $(this).parent().find('.quantity');
    let count = parseInt($input.val()) - 1;
    count = count < 0 ? 1 : count;
    $input.val(count);
});
// Прибавляем кол-во по клику
$('.quantity_inner .bt_plus').click(function() {
    let $input = $(this).parent().find('.quantity');
    let count = parseInt($input.val()) + 1;
    count = count > parseInt($input.data('max-count')) ? parseInt($input.data('max-count')) : count;
    $input.val(parseInt(count));
}); 
// Убираем все лишнее и невозможное при изменении поля
$('.quantity_inner .quantity').bind("change keyup input click", function() {
    if (this.value.match(/[^0-9]/g)) {
        this.value = this.value.replace(/[^0-9]/g, '');
    }
    if (this.value == "") {
        this.value = 1;
    }
    if (this.value > parseInt($(this).data('max-count'))) {
        this.value = parseInt($(this).data('max-count'));
    }    
});
.quantity_inner * {
    box-sizing: border-box;    
}    
.quantity_inner {
    display: flex;
    justify-content: center;
}        
.quantity_inner .bt_minus,
.quantity_inner .bt_plus,
.quantity_inner .quantity {
    color: #BFE2FF;
    height: 40px;
    width: 40px;
    padding: 0;
    margin: 10px 2px;
    border-radius: 10px;
    border: 4px solid #BFE2FF;
    background: #337AB7;
    cursor: pointer;
    outline: 0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2), 0 4px 6px rgba(0,0,0,0.2);
}
.quantity_inner .quantity {
    width: 50px;
    text-align: center;
    font-size: 22px;
    color: #FFF;
    font-family:Menlo,Monaco,Consolas,"Courier New",monospace;
}
.quantity_inner .bt_minus svg,
.quantity_inner .bt_plus svg {
    stroke: #BFE2FF;
    stroke-width: 4;
    transition: 0.5s;
    margin: 4px;
}    
.quantity_inner .bt_minus:hover svg,
.quantity_inner .bt_plus:hover svg {
    stroke: #FFF;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<input name="price" id="price" type="hidden" value="534">
<div id="price1" class="param__value"><div style="margin-right: 10px;color: #000;background: #ffca00;line-height: 21px;padding: 0 6px 0;border-radius: 4px;font-weight: 600;font-size: 14px;">790 ₽</div></div>

<div class="quantity_inner">        
    <a href="javascript:;" class="bt_minus">
        <svg viewBox="0 0 24 24"><line x1="5" y1="12" x2="19" y2="12"></line></svg>
    </a>
    <input type="text" value="0" size="2" class="quantity" data-max-count="4" />
    <a href="javascript:;" class="bt_plus">
        <svg viewBox="0 0 24 24"><line x1="12" y1="5" x2="12" y2="19"></line><line x1="5" y1="12" x2="19" y2="12"></line></svg>
    </a>
</div>
---------------------------------
<div class="quantity_inner">        
    <a href="javascript:;" class="bt_minus">
        <svg viewBox="0 0 24 24"><line x1="5" y1="12" x2="19" y2="12"></line></svg>
    </a>
    <input type="text" value="0" size="2" class="quantity" data-max-count="4" />
    <a href="javascript:;" class="bt_plus">
        <svg viewBox="0 0 24 24"><line x1="12" y1="5" x2="12" y2="19"></line><line x1="5" y1="12" x2="19" y2="12"></line></svg>
    </a>
</div> 

javascript
  • 1 个回答
  • 41 Views
Martin Hope
Вова Ханов
Asked: 2025-04-19 21:02:56 +0000 UTC

为什么文本文件被删除? Python

  • 4
def save(v,file,strnum=None):
    path = file
    if strnum ==None:
        sc_any = open(file=path,mode='w')
        sc_any.write(str(v))
        sc_any.close()
    else:
        sc_any = open(file=path,mode='r')
        lit = sc_any.readlines()
        sc_any = open(file=path,mode='w')
        lit[int(strnum)]=str(v)
        sc_any.writelines(lit)
        sc_any.close()

执行该函数时,文本文件只是被简单地删除,也就是将整个文件转换为“”。我该如何解决这个问题,也许我错过了什么?在运行此功能之前我没有写任何可能导致此结果的内容。

python
  • 1 个回答
  • 74 Views
Martin Hope
VaNoo00
Asked: 2025-04-19 15:49:39 +0000 UTC

给出了一个一维整数数组。将数字 k 插入到所有包含数字 1 的元素之前。这必须使用右移来完成

  • 5

我找不到代码中的错误,改变时数组输出不正确。

在此处输入图片描述

static void Main(string[] args)
{
    Console.WriteLine("Введите размерность массива");
    int n = Convert.ToInt32(Console.ReadLine());
    int[] m = new int[n * 2];
    int k = 0;
    Random r = new Random();
    Console.WriteLine("Начальный массив");

    for (int i = 0; i < n; i++)
    {
        m[i] = r.Next(-100, 100);
        Console.Write("{0,5}", m[i]);
    }
    Console.WriteLine();

    int a = 0;
    int count = 0;
    for (int i = 0; i < n; i++)  
    {
        int d = 0;
        a = Math.Abs(m[i]);
        while (a > 0)
        {
            if (a % 10 == 1)
            {
                d = 1;
            }
            a /= 10;
        }
        if (d == 1)
        {
            count++;

            for (int p = n + count - 1; p > i + count - 1; p--)
            {
                m[p] = m[p - 1];
            }

            m[i + count - 1] = k;
            i++;

        }
    }

    Console.WriteLine("Измененный массив");
    for (int i = 0; i < n + count; i++)
    {
        Console.Write("{0,5}", m[i]);
    }
    Console.WriteLine();
}
c#
  • 2 个回答
  • 76 Views
Martin Hope
Alex
Asked: 2025-04-18 02:51:05 +0000 UTC

如何以最小的延迟循环更新 DOM?

  • 6

我在浏览器控制台中输入以下代码http://localhost:8080/
:

async function my() {

   document.getElementsByTagName("body")[0].innerHTML = "";     
   let p = document.createElement('pre');
   
   let cnt = 0;

   for (let i = 0; i < 10000000; i++) {
    
    let now = new Date();
    let start_sec = now.getSeconds();

    if (start_sec % 5 == 0) {
        cnt = cnt + 1;
        let dmy =  now.getDate() + "." +  (now.getMonth() + 1) + "." + now.getFullYear();
        let hms_ms = now.getHours() + ":" +  now.getMinutes() + ":" + start_sec + "__" + now.getMilliseconds();

        p.innerHTML = "{\"site\": \"site_01\", \"id\": " + cnt + ", \"data\": ["  + dmy + ", " + hms_ms  + "]}";
        document.body.append(p);
    }
    
    await sleep(1000);
   }
}

function sleep(ms) {
   return new Promise(resolve => setTimeout(resolve, ms));
}

my();

我每 5 秒更新一次时间并将其显示在浏览器窗口中,例如,如下所示:

{"site": "site_01", "id": 62, "data": [17.4.2025, 21:4:35__576]}

代码运行正常,但是当延迟时间减少(await sleep(1000);
例如 200 毫秒)时,数据id和__ms。

如何修复代码以使其以尽可能小的延迟工作,例如最多 100 毫秒?

剧透我不明白如何在这里做到这一点(对于代码的第二个版本):

my();
function my() {
    
    document.getElementsByTagName("body")[0].innerHTML = "";     
    let p = document.createElement('pre');
    let cnt = 0;

    (function iterate(i) {
        
        if (i < 10000000) {
        let now = new Date();
        let start_sec = now.getSeconds();

        if (start_sec % 5 == 0) {
            cnt = cnt + 1;
            let dmy =  now.getDate() + "." +  (now.getMonth() + 1) + "." + now.getFullYear();
            let hms_ms = now.getHours() + ":" +  now.getMinutes() + ":" + start_sec + "__" + now.getMilliseconds();

            p.innerHTML = "{\"site\": \"site_01\", \"id\": " + cnt + ", \"data\": ["  + dmy + ", " + hms_ms  + "]}";
            document.body.append(p);
         }
         setTimeout(function() { iterate(i + 1); }, 10);
         }
    })(0);
}
javascript
  • 1 个回答
  • 35 Views
Martin Hope
111vkg1
Asked: 2025-04-17 23:57:53 +0000 UTC

fstream 导致程序崩溃,但只有通过 IDE 一切才能正常工作

  • 5

我正在编写一个游戏并创建了一个地图加载器和日志。加载一个块只能有效一次,当再次加载时一切都会崩溃。代码:

    logout << "[CORE]: [LOAD]: [LOADCLUSTER]: <info>: in_time: [" << (GetTime().c_str()) << "]: Entered in LoadCluster function" << '\n';
    ifstream in_data;
    string nameclst = "files/worldinfo/cluster_" + to_string(x) + "_" + to_string(y) + ".clst";
    logout << "[CORE]: [LOAD]: [LOADCLUSTER]: <info>: in_time: [" << (GetTime().c_str()) << "]: Loading data from: " << nameclst << '\n';
    in_data.open(nameclst, ios::in);
    cout << "reading information from cluster: " << nameclst << "\n";
    string in_dstr = "";
    loadedCluster = {x, y};
    unsigned int line = 0;
    while(1)
    {
        getline(in_data, in_dstr);
        if(in_dstr == "end")
            break;
        if(in_dstr == "start")
            getline(in_data, in_dstr); line++;
        if(in_dstr == " "){
            logout << "[CORE]: [LOAD]: [LOADCLUSTER]: <error>: in_time: [" << (GetTime().c_str()) << "]: File: " << nameclst << " breaked or have no information" << '\n';
            MessageBox(NULL, (string("Cannot load information from cluster: ") + (nameclst)).c_str(), "Engine error", MB_ICONWARNING | MB_OK);
            return 1;
            break;
        }
        //обработка строки
        line++;
        _sleep(1);
    }

日志通常都很糟糕。如果通过 IDE 运行它,它会读取并重写所有日志,但如果在没有 IDE 的情况下通过 exe 运行它,则在进入该函数时一切都会崩溃。代码:

void CreateNewLog()
{
    string witinglogs = "";
    witinglogs += "[SYSTEM]: <info>: in_time: [" + string(GetTime().c_str()) + "]: CORE started" + '\n';
    witinglogs += "[CORE]: [LOGS]: <info>: in_time: [" + string(GetTime().c_str()) + "]: Mathing logs" + '\n';
    ifstream logCount("logs/logCount.math");
    logout.close();
    ifstream login("logs/latestLog.log");
    string logs;
    getline(logCount, logs);
    int logsc = stoi(logs);
    logCount.close();
    ofstream logCounte("logs/logCount.math");
    logCounte << logsc + 1;
    witinglogs += "[CORE]: [LOGS]: <info>: in_time: [" + string(GetTime().c_str()) + "]: Mathed " + to_string(logsc) + " logs" + "\n";
    string logtr = "logs/Log#" + to_string(logsc) + ".log";
    ofstream logOld(logtr);
    string readedLog = "";
    getline(login, readedLog);
    witinglogs += "[CORE]: [LOGS]: <info>: in_time: [" + string(GetTime().c_str()) + "]: Rewriting logs" + "\n";
    int lines = 0;
    while(readedLog != "[QUIT]")
    {
        lines++;
        if(readedLog == "[QUIT]" || lines >= 100000)
            break;
        logOld << readedLog << '\n';
        getline(login, readedLog);
    }
    logOld << "[QUIT]";
    witinglogs += "[CORE]: [LOGS]: <info>: in_time: [" + string(GetTime().c_str()) + "]: Rewrited " + to_string(lines) + " lines" + "\n";
    logOld.close();
    login.close();
    logout.open("logs\\latestLog.log", ios_base::trunc);
    logout << witinglogs;
}

我使用 IDE Code::Blocs。

c++
  • 1 个回答
  • 58 Views
上一页
下一页

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5