<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>吾爱去(52qu)</title><link>http://www.52qu.com/</link><description>壹曲阳勇发布个人作品之网站</description><generator>RainbowSoft Studio Z-Blog 2.3 Avengers Build 180518</generator><language>zh-CN</language><pubDate>Sun, 26 Jan 2025 21:10:37 +0800</pubDate><item><title>数字验证游戏</title><author>wincao@52qu.com (程序员)</author><link>http://www.52qu.com/post/46.html</link><pubDate>Sun, 26 Jan 2025 16:02:47 +0800</pubDate><guid>http://www.52qu.com/post/46.html</guid><description><![CDATA[<p style="padding: 0px; margin-top: 0px; margin-bottom: 10px; color: rgb(34, 34, 34); font-family: 微软雅黑, 宋体, &quot;Trebuchet MS&quot;, Tahoma, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);">使用通义AI制件的网页游戏。</p><p style="padding: 0px; margin-top: 0px; margin-bottom: 10px; color: rgb(34, 34, 34); font-family: 微软雅黑, 宋体, &quot;Trebuchet MS&quot;, Tahoma, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);">点击进入游戏：<a href="http://www.52qu.com/DigitalV.html" target="_self" textvalue="数字验证游戏">数字验证游戏</a></p><!--more--><p><span style="font-size: 16px;"><strong><span style="text-wrap: nowrap;">生成随机数字：</span></strong></span></p><p><span style="text-wrap: nowrap;"><br/></span></p><p><span style="text-wrap: nowrap;"></span></p><p>生成的随机数字中每个数字都与其他位置的数字不同。</p><p>数字范围为1到9。</p><p><br/></p><p>用户输入控件：</p><p>每个输入框的范围限定在1到9之间。</p><p>输入框的数量与用户指定的长度一致。</p><p><br/></p><p>验证逻辑：</p><p>计算正确位置的数量：如果用户输入的数字与对应位置的随机数字相同，则计数加一。</p><p>计算正确数字的数量：通过统计每个数字出现的次数，确保正确数字的数量是用户输入和随机数字中共有的最小次数。</p><p><br/></p><p>显示验证结果：</p><p>验证结果显示在页面上，并区分正确和错误的消息。</p><p>正确消息显示为绿色，错误消息显示为红色。</p><p><span style="text-wrap: nowrap;"></span><br/></p><hr/><blockquote><p>&lt;!DOCTYPE html&gt;</p><p>&lt;html&gt;</p><p>&lt;head&gt;</p><p>&nbsp; &nbsp; &lt;meta charset=&quot;UTF-8&quot;&gt;</p><p>&nbsp; &nbsp; &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;</p><p>&nbsp; &nbsp; &lt;title&gt;数字验证游戏&lt;/title&gt;</p><p>&nbsp; &nbsp; &lt;style&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; body {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-family: Arial, sans-serif;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin: 20px;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; .container {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; max-width: 400px;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin: auto;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; input[type=&quot;number&quot;] {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width: 50px;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin-right: 5px;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; button {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin-top: 10px;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; .message-list {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin-top: 10px;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; .message-item {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin-bottom: 5px;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; .correct {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; color: green;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; .incorrect {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; color: red;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &lt;/style&gt;</p><p>&lt;/head&gt;</p><p>&lt;body&gt;</p><p>&nbsp; &nbsp; &lt;div&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;h1&gt;数字验证游戏&lt;/h1&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;label for=&quot;length&quot;&gt;选项中的值（生成的随机数字个数）:&lt;/label&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=&quot;number&quot; id=&quot;length&quot; min=&quot;1&quot; max=&quot;9&quot; value=&quot;4&quot;&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;button onclick=&quot;startGame()&quot;&gt;开始&lt;/button&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;br&gt;&lt;br&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;div id=&quot;userInputContainer&quot;&gt;&lt;/div&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;button id=&quot;validateButton&quot; onclick=&quot;validateInput()&quot; disabled&gt;验证&lt;/button&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;div id=&quot;messageList&quot;&gt;&lt;/div&gt;</p><p>&nbsp; &nbsp; &lt;/div&gt;</p><p><br/></p><p>&nbsp; &nbsp; &lt;script&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; let randomNumbers = [];</p><p><br/></p><p>&nbsp; &nbsp; &nbsp; &nbsp; function startGame() {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const length = parseInt(document.getElementById(&#39;length&#39;).value);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (length &gt; 9) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; displayMessage(&#39;生成的随机数字个数不能超过9&#39;, false);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; randomNumbers = generateUniqueRandomNumbers(length);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createInputControls(length);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.getElementById(&#39;validateButton&#39;).disabled = false;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clearMessages(); // 清空消息</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p><br/></p><p>&nbsp; &nbsp; &nbsp; &nbsp; function generateUniqueRandomNumbers(length) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const numbers = new Set();</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while (numbers.size &lt; length) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; numbers.add(Math.floor(Math.random() * 9) + 1);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return Array.from(numbers);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p><br/></p><p>&nbsp; &nbsp; &nbsp; &nbsp; function createInputControls(length) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const container = document.getElementById(&#39;userInputContainer&#39;);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; container.innerHTML = &#39;&#39;; // Clear previous inputs</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (let i = 0; i &lt; length; i++) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const input = document.createElement(&#39;input&#39;);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; input.type = &#39;number&#39;;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; input.min = 1;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; input.max = 9;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; input.step = 1;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; input.placeholder = &#39;输入数字&#39;;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; container.appendChild(input);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p><br/></p><p>&nbsp; &nbsp; &nbsp; &nbsp; function validateInput() {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const inputs = document.querySelectorAll(&#39;#userInputContainer input&#39;);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const userInput = Array.from(inputs).map(input =&gt; parseInt(input.value));</p><p><br/></p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (userInput.some(isNaN)) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; displayMessage(&#39;请输入有效的数字&#39;, false);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p><br/></p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let correctPositions = 0;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let correctDigits = 0;</p><p><br/></p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Calculate correct positions</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; userInput.forEach((digit, index) =&gt; {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (digit === randomNumbers[index]) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; correctPositions++;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });</p><p><br/></p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Calculate correct digits</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const userDigitCount = {};</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const randomDigitCount = {};</p><p><br/></p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; userInput.forEach(digit =&gt; {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; userDigitCount[digit] = (userDigitCount[digit] || 0) + 1;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });</p><p><br/></p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; randomNumbers.forEach(digit =&gt; {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; randomDigitCount[digit] = (randomDigitCount[digit] || 0) + 1;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });</p><p><br/></p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (const digit in userDigitCount) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (randomDigitCount[digit]) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; correctDigits += Math.min(userDigitCount[digit], randomDigitCount[digit]);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p><br/></p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (correctPositions === randomNumbers.length) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; displayMessage(`正确！您输入的数字完全正确。 输入的数字: ${userInput.join(&#39;&#39;)}`, true);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; displayMessage(`正确位置: ${correctPositions}, 正确数字: ${correctDigits}. 输入的数字: ${userInput.join(&#39;&#39;)}`, false);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p><br/></p><p>&nbsp; &nbsp; &nbsp; &nbsp; function displayMessage(message, isCorrect) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const messageList = document.getElementById(&#39;messageList&#39;);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const messageItem = document.createElement(&#39;div&#39;);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; messageItem.className = &#39;message-item&#39;;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; messageItem.textContent = message;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (isCorrect) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; messageItem.classList.add(&#39;correct&#39;);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; messageItem.classList.add(&#39;incorrect&#39;);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; messageList.appendChild(messageItem);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p><br/></p><p>&nbsp; &nbsp; &nbsp; &nbsp; function clearMessages() {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const messageList = document.getElementById(&#39;messageList&#39;);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; messageList.innerHTML = &#39;&#39;; // Clear all messages</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &lt;/script&gt;</p><p>&lt;/body&gt;</p><p>&lt;/html&gt;</p><p><br/></p><p><br/></p><p><span style="text-wrap: nowrap"><br/></span></p><p><br/></p></blockquote>]]></description><category>游戏</category><comments>http://www.52qu.com/post/46.html#comment</comments><wfw:commentRss>http://www.52qu.com/feed.asp?cmt=46</wfw:commentRss></item><item><title>专注力与记忆训练</title><author>wincao@52qu.com (程序员)</author><link>http://www.52qu.com/post/45.html</link><pubDate>Sun, 26 Jan 2025 10:52:19 +0800</pubDate><guid>http://www.52qu.com/post/45.html</guid><description><![CDATA[<p style="padding: 0px; margin-top: 0px; margin-bottom: 10px; color: rgb(34, 34, 34); font-family: 微软雅黑, 宋体, &quot;Trebuchet MS&quot;, Tahoma, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);">使用通义AI制件的网页游戏。</p><p style="padding: 0px; margin-top: 0px; margin-bottom: 10px; color: rgb(34, 34, 34); font-family: 微软雅黑, 宋体, &quot;Trebuchet MS&quot;, Tahoma, Arial, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);">点击进入游戏：<a href="http://www.52qu.com/exercise.html" target="_self" textvalue="专注力与记忆训练">专注力与记忆训练</a></p><!--more--><p><span style="font-size: 16px;"><strong>生成随机数字</strong></span><span style="text-wrap: nowrap;">：</span></p><p><span style="text-wrap: nowrap;">在点击“开始”按钮时，生成4个随机数字（每个数字范围为1到9）。</span></p><p><br/></p><p><span style="text-wrap: nowrap;">显示数字：</span></p><p><span style="text-wrap: nowrap;">将这4个随机数字分别显示在4个小窗口中。</span></p><p><span style="text-wrap: nowrap;">每个小窗口的位置和大小可以自由调整，不再固定长宽比。</span></p><p><span style="text-wrap: nowrap;">数字在小窗口中的位置是随机的。</span></p><p><br/></p><p><span style="text-wrap: nowrap;">控制显示方式：</span></p><p><span style="text-wrap: nowrap;">提供一个选项让用户选择是否同时显示所有数字。</span></p><p><span style="text-wrap: nowrap;">如果选择“同时显示”，所有数字会在同一时间显示，并在设定的时间后消失。</span></p><p><span style="text-wrap: nowrap;">如果不选择“同时显示”，数字会依次逐个显示，每次显示一个数字，并在设定的时间后继续下一个数字的显示。</span></p><p><span style="text-wrap: nowrap;"><br/></span></p><p><span style="text-wrap: nowrap;">用户输入验证：</span><br/></p><p><span style="text-wrap: nowrap;">用户需要在指定时间内记住这些数字，并在提示后输入他们所看到的数字序列。</span></p><p><span style="text-wrap: nowrap;">输入框用于接收用户的输入，最大长度为4位数字。</span></p><p><span style="text-wrap: nowrap;">验证按钮初始状态为禁用，只有在点击“开始”按钮后才启用。</span></p><p><br/></p><p><span style="text-wrap: nowrap;">验证结果：</span></p><p><span style="text-wrap: nowrap;">用户输入完成后，点击“验证”按钮进行验证。</span></p><p><span style="text-wrap: nowrap;">如果输入正确，弹出提示信息“正确！您输入的数字完全正确。”。</span></p><p><span style="text-wrap: nowrap;">如果输入错误，弹出提示信息“错误！正确的数字是：XXX”。</span></p><p><br/></p><p><span style="text-wrap: nowrap;">统计次数：</span></p><p><span style="text-wrap: nowrap;">记录并显示总的正确次数和错误次数。</span></p><p><span style="text-wrap: nowrap;">不再显示本轮的正确次数和错误次数。</span></p><p><span style="text-wrap: nowrap;">一旦用户进行了验证，无论结果如何，都会禁用验证按钮，防止二次验证。</span></p><p><br/></p><p><span style="text-wrap: nowrap;">控件布局：</span></p><p><span style="text-wrap: nowrap;">所有控件（包括下拉菜单、输入框、按钮等）放置在页面的最下方。</span></p><p><span style="text-wrap: nowrap;">标题和其他信息位于页面上方。</span></p><p><span style="text-wrap: nowrap;"><br/></span></p><p><span style="text-wrap: nowrap;">界面设计：</span></p><p><span style="text-wrap: nowrap;">页面整体背景颜色为浅灰色 (#f0f0f0)。</span></p><p><span style="text-wrap: nowrap;">使用简单的CSS样式来美化小窗口和控件。</span></p><p><span style="text-wrap: nowrap;"><br/></span></p><p><span style="text-wrap: nowrap;">通过以上需求，程序旨在帮助用户提高专注力和记忆力。希望这些需求对您有所帮助！如果有进一步的修改或扩展需求，请随时告知。</span></p><hr class="more"/><blockquote><p><span style="text-wrap: nowrap">&lt;!DOCTYPE html&gt;</span></p><p><span style="text-wrap: nowrap">&lt;html&gt;</span></p><p><span style="text-wrap: nowrap">&lt;head&gt;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &lt;meta charset=&quot;UTF-8&quot;&gt;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &lt;style&gt;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; body, html {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin: 0;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padding: 0;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height: 100%;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; display: flex;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; justify-content: center;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; align-items: center;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background-color: #f0f0f0;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; flex-direction: column;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; .container {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width: 90%; /* Relative width */</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height: 50vh; /* Relative height */</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; display: grid;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid-template-columns: repeat(2, 1fr);</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; grid-template-rows: repeat(2, 1fr);</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gap: 10px;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin-bottom: 20px;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; .box {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; position: relative;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background-color: white;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; border: 1px solid #ccc;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; display: flex;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; justify-content: center;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; align-items: center;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; .number {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; position: absolute;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-size: 2em;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; color: #333;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; .controls {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; display: flex;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; justify-content: center;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; align-items: center;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin-top: 10px;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; .controls select, .controls input, .controls button {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin: 0 10px;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padding: 10px;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-size: 1em;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; h1 {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text-align: center;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin-bottom: 10px;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; .stats {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin-top: 20px;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; font-size: 1.5em;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; color: #333;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &lt;/style&gt;</span></p><p><span style="text-wrap: nowrap">&lt;/head&gt;</span></p><p><span style="text-wrap: nowrap">&lt;body&gt;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &lt;h1&gt;专注力与记忆训练&lt;/h1&gt;</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &lt;div id=&quot;container&quot;&gt;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &lt;!-- Boxes will be dynamically added here --&gt;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &lt;/div&gt;</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &lt;div id=&quot;statsMessage&quot;&gt;&lt;/div&gt;</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &lt;div&gt;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &lt;select id=&quot;timeSelect&quot;&gt;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;option value=&quot;1&quot;&gt;1 秒&lt;/option&gt;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;option value=&quot;3&quot;&gt;3 秒&lt;/option&gt;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;option value=&quot;5&quot;&gt;5 秒&lt;/option&gt;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;option value=&quot;7&quot;&gt;7 秒&lt;/option&gt;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &lt;/select&gt;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &lt;button id=&quot;startButton&quot;&gt;开始&lt;/button&gt;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=&quot;text&quot; id=&quot;userInput&quot; placeholder=&quot;请输入4位数字&quot; maxlength=&quot;4&quot; disabled&gt;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &lt;button id=&quot;validateButton&quot; disabled&gt;验证&lt;/button&gt;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &lt;label&gt;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=&quot;checkbox&quot; id=&quot;simultaneousDisplayCheckbox&quot;&gt;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 同时显示数字</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &lt;/label&gt;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &lt;/div&gt;</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &lt;script&gt;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; let displayedNumbers = [];</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; let correctCount = 0;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; let incorrectCount = 0;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; let validationAllowed = true;</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; function getRandomNumber() {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return Math.floor(Math.random() * 9) + 1;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; function getRandomPosition(boxWidth, boxHeight, numberWidth, numberHeight) {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const maxX = boxWidth - numberWidth;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const maxY = boxHeight - numberHeight;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x: Math.floor(Math.random() * maxX),</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y: Math.floor(Math.random() * maxY)</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; };</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; function updateBox(box, number) {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const randomPosition = getRandomPosition(</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; box.offsetWidth,</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; box.offsetHeight,</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 50, // Assuming the number width is 50px</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 50&nbsp; // Assuming the number height is 50px</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const numberElement = document.createElement(&#39;div&#39;);</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; numberElement.className = &#39;number&#39;;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; numberElement.style.left = `${randomPosition.x}px`;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; numberElement.style.top = `${randomPosition.y}px`;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; numberElement.textContent = number;</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; box.innerHTML = &#39;&#39;; // Clear previous numbers</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; box.appendChild(numberElement);</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; function createBoxes(numBoxes) {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const container = document.getElementById(&#39;container&#39;);</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; container.innerHTML = &#39;&#39;; // Clear existing boxes</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Set grid template based on the number of boxes</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (numBoxes === 4) {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; container.style.gridTemplateColumns = &#39;repeat(2, 1fr)&#39;;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; container.style.gridTemplateRows = &#39;repeat(2, 1fr)&#39;;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (let i = 0; i &lt; numBoxes; i++) {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const box = document.createElement(&#39;div&#39;);</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; box.className = &#39;box&#39;;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; container.appendChild(box);</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; document.getElementById(&#39;startButton&#39;).addEventListener(&#39;click&#39;, () =&gt; {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const boxes = document.querySelectorAll(&#39;.box&#39;);</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const selectedTime = parseInt(document.getElementById(&#39;timeSelect&#39;).value);</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const simultaneousDisplay = document.getElementById(&#39;simultaneousDisplayCheckbox&#39;).checked;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; displayedNumbers = [];</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const userInputField = document.getElementById(&#39;userInput&#39;);</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const validateButton = document.getElementById(&#39;validateButton&#39;);</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Reset validation status</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; validationAllowed = true;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; userInputField.disabled = false;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; validateButton.disabled = false;</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Clear any existing intervals and result message</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clearInterval(intervalId);</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clearTimeout(timeoutId);</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; userInputField.value = &#39;&#39;;</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Generate random numbers based on the number of boxes</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (let i = 0; i &lt; boxes.length; i++) {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const randomNumber = getRandomNumber();</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; displayedNumbers.push(randomNumber);</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (simultaneousDisplay) {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Display all numbers simultaneously with random positions</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; boxes.forEach((box, index) =&gt; {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; updateBox(box, displayedNumbers[index]);</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Clear all boxes after the selected time</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; timeoutId = setTimeout(() =&gt; {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; boxes.forEach(box =&gt; {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; box.innerHTML = &#39;&#39;;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }, selectedTime * 1000);</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Function to update each box in sequence with random positions</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let currentBoxIndex = 0;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function updateNextBox() {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (currentBoxIndex &lt; boxes.length) {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; updateBox(boxes[currentBoxIndex], displayedNumbers[currentBoxIndex]);</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currentBoxIndex++;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setTimeout(updateNextBox, selectedTime * 1000);</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // All boxes have been updated</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Wait for the selected time before clearing all boxes</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; timeoutId = setTimeout(() =&gt; {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; boxes.forEach(box =&gt; {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; box.innerHTML = &#39;&#39;;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }, selectedTime * 1000);</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Start updating boxes every second</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; intervalId = setTimeout(updateNextBox, 1000);</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; });</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; document.getElementById(&#39;validateButton&#39;).addEventListener(&#39;click&#39;, () =&gt; {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!validationAllowed) {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert(&quot;您已经验证过这一轮了，请点击“开始”按钮重新生成数字。&quot;);</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const userInputField = document.getElementById(&#39;userInput&#39;);</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const userInput = userInputField.value.trim();</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Validate user input</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (userInput.length === displayedNumbers.length &amp;&amp; /^\d+$/.test(userInput)) {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const userNumbers = userInput.split(&#39;&#39;).map(Number);</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Compare user input with displayed numbers</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let correct = true;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (let i = 0; i &lt; displayedNumbers.length; i++) {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (userNumbers[i] !== displayedNumbers[i]) {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; correct = false;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Update stats</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (correct) {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; correctCount++;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; incorrectCount++;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Display result in a popup</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (correct) {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert(&quot;正确！您输入的数字完全正确。&quot;);</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert(`错误！正确的数字是：${displayedNumbers.join(&#39;&#39;)}`);</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Update total stats message</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const statsMessage = document.getElementById(&#39;statsMessage&#39;);</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; statsMessage.textContent = `总正确次数: ${correctCount}, 总错误次数: ${incorrectCount}`;</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Disable further validation</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; validationAllowed = false;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; userInputField.disabled = true;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; validateButton.disabled = true;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert(`无效输入。请输入正好${displayedNumbers.length}位数字。`);</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; });</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; let intervalId;</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; let timeoutId;</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; // Initialize with 4 boxes by default</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &nbsp; &nbsp; createBoxes(4);</span></p><p><span style="text-wrap: nowrap">&nbsp; &nbsp; &lt;/script&gt;</span></p><p><span style="text-wrap: nowrap">&lt;/body&gt;</span></p><p><span style="text-wrap: nowrap">&lt;/html&gt;</span></p><p><span style="text-wrap: nowrap"><br/></span></p><p><br/></p></blockquote><p><br/></p>]]></description><category>游戏</category><comments>http://www.52qu.com/post/45.html#comment</comments><wfw:commentRss>http://www.52qu.com/feed.asp?cmt=45</wfw:commentRss></item><item><title>【C#】以执行频率打印进度，即文字进度条</title><author>wincao@52qu.com (程序员)</author><link>http://www.52qu.com/post/44.html</link><pubDate>Tue, 05 Mar 2024 18:32:38 +0800</pubDate><guid>http://www.52qu.com/post/44.html</guid><description><![CDATA[<p><strong><span style="font-size: 24px;">难点在最后输出100%问题</span></strong>。<br/>经过多次实践，终于找出解决：<br/></p><blockquote><p>&nbsp; &nbsp;<br/></p><p>/// &lt;summary&gt;</p><p>/// 以执行频率打印进度</p><p>/// &lt;/summary&gt;</p><p>/// &lt;param name=&quot;Max&quot;&gt;最大值&lt;/param&gt;</p><p>/// &lt;param name=&quot;Y&quot;&gt;执行频率&lt;/param&gt;</p><p>public&nbsp;static&nbsp;void&nbsp;Do(Action work,&nbsp;double&nbsp;Max,&nbsp;double&nbsp;Y = 0.01)</p><p>{</p><p>&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;current = 0;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(int&nbsp;i = 0; i &lt; Max; i++)</p><p>&nbsp;&nbsp;&nbsp;&nbsp;{</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//百分之一时反馈</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;((int)(current++ % (Max * Y)) == 0)</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine($&quot;已经完成{current}个，进度{Math.Floor(current / (Max * 0.01))}%。&quot;);</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//工作代码</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;work();</p><p>&nbsp;&nbsp;&nbsp;&nbsp;}</p><p>&nbsp;&nbsp;&nbsp;&nbsp;//补充100%的输出</p><p>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;((int)((current - 1) % (Max * Y)) != 0)</p><p>&nbsp;&nbsp;&nbsp;&nbsp;{</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine($&quot;已经完成{current}个，进度{Math.Floor(current / (Max * 0.01))}%。&quot;);</p><p>&nbsp;&nbsp;&nbsp;&nbsp;}</p><p>}</p><p>&nbsp;</p><p>public&nbsp;static&nbsp;void&nbsp;work()</p><p>{</p><p>&nbsp;&nbsp;&nbsp;&nbsp;//工作代码</p><p>&nbsp;&nbsp;&nbsp;&nbsp;Thread.Sleep(100);</p><p>}</p><p>&nbsp; &nbsp;</p></blockquote><p><br/></p><p><br/><br/>执行代码：<br/></p><blockquote><p><br/></p><p>//以执行频率打印进度</p><p>Class6.Do(Class6.work, 99, 0.3);</p><p>&nbsp; &nbsp;</p></blockquote><p><br/></p><p><br/><br/>最后显示结果：<br/></p><blockquote><p><br/></p><p>已经完成1个，进度1%。<br/></p><p>已经完成31个，进度31%。</p><p>已经完成61个，进度61%。</p><p>已经完成91个，进度91%。</p><p>已经完成99个，进度100%</p><p>&nbsp; &nbsp;</p><p><br/></p></blockquote><p><br/></p>]]></description><category>学习记录</category><comments>http://www.52qu.com/post/44.html#comment</comments><wfw:commentRss>http://www.52qu.com/feed.asp?cmt=44</wfw:commentRss></item><item><title>演播室提示字幕1.3 </title><author>wincao@52qu.com (程序员)</author><link>http://www.52qu.com/post/43.html</link><pubDate>Thu, 16 Mar 2023 11:09:44 +0800</pubDate><guid>http://www.52qu.com/post/43.html</guid><description><![CDATA[<table cellspacing="0" cellpadding="0" width="1661" style="width: 1514px;"><tbody style="overflow-wrap: break-word;"><tr style="overflow-wrap: break-word;" class="firstRow"><td class="t_f" id="postmessage_45945101" style="overflow-wrap: break-word; font-size: 14px;">主要用在两个屏幕的提示器，比如演播室。<br style="overflow-wrap: break-word;"/><br style="overflow-wrap: break-word;"/>一个操作屏（使用软件区），一个是显示屏（黑色部分）。<br style="overflow-wrap: break-word;"/>在软件上点某行，这行就显示到显示屏上。<br style="overflow-wrap: break-word;"/>按F12上屏或编辑文字。<br style="overflow-wrap: break-word;"/><img src="http://www.52qu.com/zb_users/upload/2023/3/2023031640224641.png"/><br style="overflow-wrap: break-word;"/><p><br/></p><p>设置页是显示区（黑色部分）的基本参数</p><img src="http://www.52qu.com/zb_users/upload/2023/3/2023031640234625.png"/></td></tr></tbody></table><p><br/></p><p>下载：<a href="http://www.52qu.com/zb_users/upload/2023/3/202303161115091582.7z" target="_blank">免安装程序</a></p>]]></description><category>工具</category><comments>http://www.52qu.com/post/43.html#comment</comments><wfw:commentRss>http://www.52qu.com/feed.asp?cmt=43</wfw:commentRss></item><item><title>微信小程序云开发</title><author>wincao@52qu.com (程序员)</author><link>http://www.52qu.com/post/42.html</link><pubDate>Tue, 01 Nov 2022 10:09:32 +0800</pubDate><guid>http://www.52qu.com/post/42.html</guid><description><![CDATA[<p>前言</p><p>因为微信云开发开始收费了，没有免费基础云，还好目前（2022年）阿里云可以免费使用，所以将自己注册使用方法分享出来。</p><!--more--><p style="margin-left: 28px"><span style="font-family:Calibri;font-size:14px">1.&nbsp;</span><span style=";font-family:宋体;font-size:14px">在使用</span><span style=";font-family:宋体;font-size:14px">阿里</span><span style=";font-family:宋体;font-size:14px"><span style="font-family:宋体">云</span>SDK<span style="font-family:宋体">前，请确保已经正确安装了</span><span style="font-family:Calibri">Node.js</span><span style="font-family:宋体">开发环境。</span></span></p><p style="margin-left:56px"><span style="font-family:Calibri;font-size:14px">(1)&nbsp;</span><a href="http://nodejs.cn/，下载文件并安装。"><span style="text-decoration:underline;"><span style="color: rgb(0, 0, 255)">http://nodejs.cn/</span></span><span style="text-decoration:underline;"><span style="color: rgb(0, 0, 255)"><span style="font-family:宋体">，</span></span></span><span style="text-decoration:underline;"><span style="color: rgb(0, 0, 255)"><span style="font-family:宋体">下载文件并安装。</span></span></span></a></p><p style="margin-left: 28px"><span style="font-family:Calibri;font-size:14px">2.&nbsp;</span><span style=";font-family:宋体;font-size:14px"><span style="font-family:宋体">创建微信小程序。登录微信公众平台，在开发设置页面查看</span>App ID<span style="font-family:宋体">，建立密钥</span></span></p><p><span style=";font-family:Calibri;font-size:14px"><img src="http://www.52qu.com/zb_users/upload/2022/11/2022110136769033.png"/>&nbsp;</span></p><p style="margin-left: 28px"><span style="font-family:Calibri;font-size:14px">3.&nbsp;</span><span style=";font-family:宋体;font-size:14px"><span style="font-family:宋体">在服务器域名下，如图输入阿里云地址。具体看第</span>9<span style="font-family:宋体">条。</span></span></p><p><span style=";font-family:Calibri;font-size:14px"><img src="http://www.52qu.com/zb_users/upload/2022/11/2022110136779609.png"/>&nbsp;</span></p><p style="margin-left: 28px"><span style="font-family:Calibri;font-size:14px">4.&nbsp;</span><span style=";font-family:宋体;font-size:14px">在微信小程序项目的根目录</span><span style=";font-family:宋体;font-size:14px">，</span><span style=";font-family:宋体;font-size:14px"><span style="font-family:宋体">输入</span>CMD<span style="font-family:宋体">，打开命令窗</span></span></p><p><img src="http://www.52qu.com/zb_users/upload/2022/11/2022110136786813.png"/><span style=";font-family:Calibri;font-size:14px">&nbsp;</span></p><p style="margin-left: 28px"><span style="font-family:Calibri;font-size:14px">5.&nbsp;</span><span style=";font-family:宋体;font-size:14px">输入</span><span style=";font-family:宋体;font-size:14px">【</span><span style=";font-family:宋体;font-size:14px">npm install --save @alicloud/mpserverless-sdk@3.1.1</span><span style=";font-family:宋体;font-size:14px">】</span><span style=";font-family:宋体;font-size:14px"><span style="font-family:宋体">执行安装</span>SDK<span style="font-family:宋体">。</span></span></p><p style="margin-left: 28px"><span style="font-family:Calibri;font-size:14px">6.&nbsp;</span><span style=";font-family:宋体;font-size:14px"><span style="font-family:宋体">在微信小程序</span>IDE<span style="font-family:宋体">中，选择工具</span><span style="font-family:Calibri">&gt;</span><span style="font-family:宋体">构建</span><span style="font-family:Calibri">npm</span><span style="font-family:宋体">。</span></span></p><p style="margin-left: 28px"><span style="font-family:Calibri;font-size:14px">7.&nbsp;</span><span style=";font-family:宋体;font-size:14px"><span style="font-family:宋体">在微信小程序项目中的</span>app.js<span style="font-family:宋体">中添加以下代码，构造小程序云</span><span style="font-family:Calibri">SDK</span><span style="font-family:宋体">的实例对象。在</span><span style="font-family:Calibri">app.js</span><span style="font-family:宋体">的</span><span style="font-family:Calibri">onLaunch</span><span style="font-family:宋体">生命周期中调用</span><span style="font-family:Calibri">init</span><span style="font-family:宋体">接口完成初始化。</span></span></p><table cellspacing="0" width="568"><tbody><tr class="firstRow"><td width="568" valign="top" style="padding: 0px 7px; border-width: 1px; border-color: windowtext;"><p><span style=";font-family:宋体;font-size:14px">// app.js</span></p><p><span style=";font-family:宋体;font-size:14px">import MPServerless from &#39;@alicloud/mpserverless-sdk&#39;;</span></p><p><span style=";font-family:宋体;font-size:14px">const mpserverless = new MPServerless(wx, {</span></p><p><span style=";font-family:宋体;font-size:14px">&nbsp;appId: &lt;<span style="font-family:宋体">您的微信小程序</span><span style="font-family:Calibri">appId&gt;,</span></span></p><p><span style=";font-family:宋体;font-size:14px">&nbsp;&nbsp;spaceId: &lt;<span style="font-family:宋体">您的</span></span><span style=";font-family:宋体;font-size:14px">阿里</span><span style=";font-family:宋体;font-size:14px">云<span style="font-family:Calibri">serverless</span><span style="font-family:宋体">服务空间</span><span style="font-family:Calibri">spaceId&gt;</span></span></p><p><span style=";font-family:宋体;font-size:14px">&nbsp;&nbsp;clientSecret: &lt;<span style="font-family:宋体">您的</span></span><span style=";font-family:宋体;font-size:14px">阿里</span><span style=";font-family:宋体;font-size:14px">云<span style="font-family:Calibri">serverless</span><span style="font-family:宋体">服务空间</span><span style="font-family:Calibri">clientSecret&gt;</span></span></p><p><span style=";font-family:宋体;font-size:14px">&nbsp;&nbsp;endpoint: &lt;<span style="font-family:宋体">您的小</span></span><span style=";font-family:宋体;font-size:14px">阿里</span><span style=";font-family:宋体;font-size:14px">云<span style="font-family:Calibri">serverless</span><span style="font-family:宋体">服务空间</span><span style="font-family:Calibri">Api endpoint&gt;</span></span></p><p><span style=";font-family:宋体;font-size:14px">});</span></p><p><span style="font-family:宋体;font-size:14px">&nbsp;</span></p><p><span style=";font-family:宋体;font-size:14px">App({</span></p><p><span style=";font-family:宋体;font-size:14px">&nbsp;&nbsp;&nbsp;&nbsp;mpserverless: mpserverless,</span></p><p><span style=";font-family:宋体;font-size:14px">&nbsp;&nbsp;&nbsp;&nbsp;onLaunch(options) {</span></p><p><span style=";font-family:宋体;font-size:14px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mpserverless.init(); </span></p><p><span style=";font-family:宋体;font-size:14px">&nbsp;&nbsp;&nbsp;&nbsp;},</span></p><p><span style=";font-family:宋体;font-size:14px">&nbsp;&nbsp;});</span></p></td></tr></tbody></table><p style="margin-left: 28px"><span style="font-family:Calibri;font-size:14px">8.&nbsp;</span><span style=";font-family:宋体;font-size:14px"><span style="font-family:宋体">其中【微信小程序</span>appId<span style="font-family:宋体">】如下图</span></span></p><p><img src="http://www.52qu.com/zb_users/upload/2022/11/2022110136795281.png"/><span style=";font-family:Calibri;font-size:14px">&nbsp;</span></p><p><span style=";font-family:Calibri;font-size:14px">&nbsp;</span></p><p style="margin-left: 28px"><span style="font-family:Calibri;font-size:14px">9.&nbsp;</span><span style=";font-family:宋体;font-size:14px">其中</span><span style=";font-family:宋体;font-size:14px">spaceId</span><span style=";font-family:宋体;font-size:14px">、</span><span style=";font-family:宋体;font-size:14px">clientSecret</span><span style=";font-family:宋体;font-size:14px">、</span><span style=";font-family:宋体;font-size:14px">endpoint</span><span style=";font-family:宋体;font-size:14px"><span style="font-family:宋体">分别为下图的</span>Space ID<span style="font-family:宋体">、</span><span style="font-family:Calibri">Secret API</span><span style="font-family:宋体">、</span><span style="font-family:Calibri">Endpoint</span></span></p><p style="margin-left: 56px"><span style="font-family:Calibri;font-size:14px">(1)&nbsp;</span><span style=";font-family:宋体;font-size:14px"><span style="font-family:宋体">注册阿里小程序云</span>https://emas.console.aliyun.com/<span style="font-family:宋体">。</span></span></p><p style="margin-left: 28px"><img src="http://www.52qu.com/zb_users/upload/2022/11/2022110136798641.png"/><span style=";font-family:Calibri;font-size:14px">&nbsp;</span></p><p style="margin-left: 56px"><span style="font-family:Calibri;font-size:14px">(2)&nbsp;</span><span style=";font-family:宋体;font-size:14px"><span style="font-family:宋体">进入项目</span>-&gt;<span style="font-family:宋体">平台服务</span></span></p><p><img src="http://www.52qu.com/zb_users/upload/2022/11/2022110136803609.png"/><span style=";font-family:Calibri;font-size:14px">&nbsp;</span></p><p style="margin-left: 28px"><span style="font-family:Calibri;font-size:14px">10.&nbsp;</span><span style=";font-family:宋体;font-size:14px">在设置中输入微信小程序的密钥</span></p><p><img src="http://www.52qu.com/zb_users/upload/2022/11/2022110136808501.png"/><span style=";font-family:Calibri;font-size:14px">&nbsp;</span></p><p style="margin-left: 28px"><span style="font-family:Calibri;font-size:14px">11.&nbsp;</span><span style=";font-family:宋体;font-size:14px">使用阿里云</span></p><table cellspacing="0" width="712"><tbody><tr class="firstRow"><td width="712" valign="top" style="padding: 0px 7px; border-width: 1px; border-color: windowtext;"><p><span style=";font-family:宋体;font-size:14px">// </span><span style=";font-family:宋体;font-size:14px">.js</span><span style=";font-family:宋体;font-size:14px">文件中使用 <span style="font-family:Calibri">sdk</span></span></p><p><span style=";font-family:宋体;font-size:14px">const { mpserverless } = getApp();</span></p><p><span style="font-family:宋体;font-size:14px">&nbsp;</span></p><p><span style=";font-family:宋体;font-size:14px">mpserverless.db.collection(&#39;test&#39;).find();</span></p><p><span style=";font-family:宋体;font-size:14px">mpserverless.function.invoke(&#39;test&#39;);</span></p></td></tr></tbody></table><p><span style=";font-family:Calibri;font-size:14px">微信小程序 成功调用！</span></p><p><span style=";font-family:Calibri;font-size:14px"><img src="http://www.52qu.com/zb_users/upload/2022/11/2022110136900281.png"/></span></p><p><br/></p>]]></description><category>编程</category><comments>http://www.52qu.com/post/42.html#comment</comments><wfw:commentRss>http://www.52qu.com/feed.asp?cmt=42</wfw:commentRss></item><item><title>《我的记事本》2022版来啦</title><author>wincao@52qu.com (程序员)</author><link>http://www.52qu.com/post/41.html</link><pubDate>Fri, 02 Sep 2022 15:48:43 +0800</pubDate><guid>http://www.52qu.com/post/41.html</guid><description><![CDATA[<p>
    《我的记事本》经过收集同事的意见和建议而修改的2022版终于来啦。<br/>
</p>
<p>
    下载：
</p>
<p>
    <a href="http://www.52qu.com/zb_users/upload/2022/9/WincaoNote3.5.zip" target="_blank" textvalue="绿色版">绿色版</a><br/>
</p>
<p>
    <a href="http://www.52qu.com/zb_users/upload/2022/9/WincaoNote4.62.zip" target="_self">安装版</a>
</p>
<!--more-->
<p>
    <br/>
</p>
<p>
    <img src="http://www.52qu.com/zb_users/upload/2022/9/2022090257089673.png"/><img src="http://www.52qu.com/zb_users/upload/2022/9/2022090257090921.png"/>
</p>]]></description><category>工具</category><comments>http://www.52qu.com/post/41.html#comment</comments><wfw:commentRss>http://www.52qu.com/feed.asp?cmt=41</wfw:commentRss></item><item><title>wpf中建立菜单快捷键</title><author>wincao@52qu.com (程序员)</author><link>http://www.52qu.com/post/40.html</link><pubDate>Fri, 13 May 2022 13:04:11 +0800</pubDate><guid>http://www.52qu.com/post/40.html</guid><description><![CDATA[<p>xaml文件</p><table><tbody><tr class="firstRow"><td width="1509" valign="top" style="word-break: break-all;"><p>&lt;Window.Resources&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;RoutedUICommand x:Key=&quot;F3&quot; Text=&quot;查找内容&quot;/&gt;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;RoutedUICommand x:Key=&quot;Search&quot; Text=&quot;查找内容&quot;/&gt;</p><p>&nbsp; &nbsp; &lt;/Window.Resources&gt;</p><p>&lt;Window.InputBindings&gt;</p><p>&nbsp; &nbsp; &lt;KeyBinding Gesture=&quot;F3&quot; Command=&quot;{StaticResource Search}&quot; /&gt;</p><p>&nbsp; &nbsp; &lt;KeyBinding Gesture=&quot;Ctrl+F&quot; Command=&quot;{StaticResource Search}&quot;/&gt;</p><p>&lt;/Window.InputBindings&gt;</p><p>&lt;Window.CommandBindings&gt;</p><p>&nbsp; &nbsp; &lt;CommandBinding Command=&quot;{StaticResource Search}&quot; Executed=&quot;CommandBindingSearch_Executed&quot;/&gt;</p><p>&nbsp; &nbsp; &lt;CommandBinding Command=&quot;{StaticResource F3}&quot; Executed=&quot;CommandBindingSearch_Executed&quot;/&gt;</p><p>&lt;/Window.CommandBindings&gt;</p><p><br/></p><p>&nbsp;&lt;MenuItem Header=&quot;查找&quot; InputGestureText=&quot;Ctrl+F&quot; Click=&quot;CommandBindingSearch_Executed&quot; /&gt;</p></td></tr></tbody></table><p><br/></p><p>cs文件</p><table><tbody><tr class="firstRow"><td width="1509" valign="top"><p style="margin-top: 5px; margin-bottom: 5px;">private void CommandBindingSearch_Executed(object sender, ExecutedRoutedEventArgs e)</p><p style="margin-top: 5px; margin-bottom: 5px;">{</p><p style="margin-top: 5px; margin-bottom: 5px;">&nbsp; &nbsp; //执行查找</p><p style="margin-top: 5px; margin-bottom: 5px;">}</p></td></tr></tbody></table><p><br/></p>]]></description><category>编程</category><comments>http://www.52qu.com/post/40.html#comment</comments><wfw:commentRss>http://www.52qu.com/feed.asp?cmt=40</wfw:commentRss></item><item><title>剪映导出字幕</title><author>wincao@52qu.com (剪辑师)</author><link>http://www.52qu.com/post/39.html</link><pubDate>Fri, 08 Apr 2022 20:34:20 +0800</pubDate><guid>http://www.52qu.com/post/39.html</guid><description><![CDATA[<p><span style="font-family: 宋体;">剪映的智能字幕，支持</span>AI<span style="font-family: 宋体;">识别字幕，方便同期声定稿，导入非编软件等。下列软件都可以在共享盘中可以找到。</span><br/></p><table cellspacing="0" cellpadding="0"><tbody><tr class="firstRow"><td width="430" valign="top" style="border: 1px solid windowtext; padding: 0px 7px;"><p class="MsoListParagraph" style="margin-left:24px">1、<span style="font:9px &#39;Times New Roman&#39;">&nbsp; </span><span style="font-family:宋体">打开【剪映】，开始创作。</span></p></td><td width="905" valign="top" style="border-top: 1px solid windowtext; border-right: 1px solid windowtext; border-bottom: 1px solid windowtext; border-image: initial; border-left: none; padding: 0px 7px;"><img src="http://www.52qu.com/zb_users/upload/2022/4/202204082040417757.png" style="white-space: normal; width: 500px; height: 338px;" width="500" height="338" border="0" hspace="0" vspace="0" title=""/><p><br/></p></td></tr><tr><td width="424" valign="top" style="border-right: 1px solid windowtext; border-bottom: 1px solid windowtext; border-left: 1px solid windowtext; border-image: initial; border-top: none; padding: 0px 7px;"><p class="MsoListParagraph" style="margin-left:24px">2、<span style="font:9px &#39;Times New Roman&#39;">&nbsp; </span><span style="font-family:宋体">【导入】视频、音频，拖下时间线。</span></p></td><td width="905" valign="top" style="border-top: none; border-left: none; border-bottom: 1px solid windowtext; border-right: 1px solid windowtext; padding: 0px 7px;"><p><img src="http://www.52qu.com/zb_users/upload/2022/4/202204082040466127.png" width="500" height="270" border="0" hspace="0" vspace="0" title="" style="width: 500px; height: 270px;"/></p></td></tr><tr><td width="424" valign="top" style="border-right: 1px solid windowtext; border-bottom: 1px solid windowtext; border-left: 1px solid windowtext; border-image: initial; border-top: none; padding: 0px 7px;"><p class="MsoListParagraph" style="margin-left:24px">3、<span style="font:9px &#39;Times New Roman&#39;">&nbsp; </span><span style="font-family:宋体">【文本】</span>-<span style="font-family:宋体">智能字幕</span>-<span style="font-family:宋体">识别字幕</span>-<span style="font-family:宋体">开始识别。</span></p><p class="MsoListParagraph" style="margin-left:24px">4、<span style="font:9px &#39;Times New Roman&#39;">&nbsp; </span><span style="font-family:宋体">后期编辑可以使用【文稿匹配】得到准确的时码。</span></p><p class="MsoListParagraph" style="margin-left:24px">5、<span style="font:9px &#39;Times New Roman&#39;">&nbsp; </span><span style="font-family:宋体">右键视频音频出现的菜单也有【识别字幕】功能</span></p></td><td width="905" valign="top" style="border-top: none; border-left: none; border-bottom: 1px solid windowtext; border-right: 1px solid windowtext; padding: 0px 7px;"><p><img src="http://www.52qu.com/zb_users/upload/2022/4/202204082040505562.png"/></p></td></tr><tr><td width="424" valign="top" style="border-right: 1px solid windowtext; border-bottom: 1px solid windowtext; border-left: 1px solid windowtext; border-image: initial; border-top: none; padding: 0px 7px;"><p class="MsoListParagraph" style="margin-left:24px">6、<span style="font:9px &#39;Times New Roman&#39;">&nbsp; </span><span style="font-family:宋体">成功出现字幕后，关闭【剪映】</span></p></td><td width="905" valign="top" style="border-top: none; border-left: none; border-bottom: 1px solid windowtext; border-right: 1px solid windowtext; padding: 0px 7px;"><p><img src="http://www.52qu.com/zb_users/upload/2022/4/202204082040540201.png" width="500" height="147" border="0" hspace="0" vspace="0" title="" style="width: 500px; height: 147px;"/></p></td></tr><tr><td width="424" valign="top" style="border-right: 1px solid windowtext; border-bottom: 1px solid windowtext; border-left: 1px solid windowtext; border-image: initial; border-top: none; padding: 0px 7px;"><p class="MsoListParagraph" style="margin-left:24px">7、<span style="font:9px &#39;Times New Roman&#39;">&nbsp; </span><span style="font-family:宋体">打开【剪映导出字幕】软件。</span></p><p class="MsoListParagraph" style="margin-left:24px">8、<span style="font:9px &#39;Times New Roman&#39;">&nbsp; </span><span style="font-family:宋体">列表中没有出现刚才新建的时间线，则要正确选择剪映目录。</span></p></td><td width="905" valign="top" style="border-top: none; border-left: none; border-bottom: 1px solid windowtext; border-right: 1px solid windowtext; padding: 0px 7px;"><p><img src="http://www.52qu.com/zb_users/upload/2022/4/202204082040581450.png"/></p></td></tr><tr><td width="424" valign="top" style="border-right: 1px solid windowtext; border-bottom: 1px solid windowtext; border-left: 1px solid windowtext; border-image: initial; border-top: none; padding: 0px 7px;"><p class="MsoListParagraph" style="margin-left:24px">9、<span style="font:9px &#39;Times New Roman&#39;">&nbsp; </span><span style="font-family:宋体">选择时间线和输出类型，点击【转换】即可。</span></p></td><td width="905" valign="top" style="border-top: none; border-left: none; border-bottom: 1px solid windowtext; border-right: 1px solid windowtext; padding: 0px 7px;"><p><br/></p></td></tr></tbody></table><p>&nbsp;</p><p><br/></p><p><a href="http://www.52qu.com/zb_users/upload/2022/4/%E5%89%AA%E6%98%A0%E5%AF%BC%E5%87%BA%E5%AD%97%E5%B9%95.publish.7z" target="_blank" style="padding: 0px; margin: 0px; text-decoration-line: none; color: rgb(29, 76, 125); font-family: 微软雅黑, 宋体, &quot;Trebuchet MS&quot;, Tahoma, Arial, sans-serif; white-space: normal; text-indent: 2.8px; background-color: rgb(255, 255, 255);">剪映导出字幕</a><span style="color: rgb(34, 34, 34); font-family: 微软雅黑, 宋体, &quot;Trebuchet MS&quot;, Tahoma, Arial, sans-serif; background-color: rgb(255, 255, 255);">：</span><a href="http://www.52qu.com/zb_users/upload/2022/4/202204082033498678.zip" target="_self" textvalue="下载" style="padding: 0px; margin: 0px; text-decoration-line: none; color: rgb(94, 170, 228); font-family: 微软雅黑, 宋体, &quot;Trebuchet MS&quot;, Tahoma, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">下载</a></p>]]></description><category>工具</category><comments>http://www.52qu.com/post/39.html#comment</comments><wfw:commentRss>http://www.52qu.com/feed.asp?cmt=39</wfw:commentRss></item><item><title>C#的listView控件使用全选</title><author>wincao@52qu.com (程序员)</author><link>http://www.52qu.com/post/38.html</link><pubDate>Fri, 08 Apr 2022 19:33:02 +0800</pubDate><guid>http://www.52qu.com/post/38.html</guid><description><![CDATA[<p>C#的listView控件使用全选。可以通过以下事件完成：</p><p>&nbsp; &nbsp; &nbsp; &nbsp; private void listView_KeyPress(object sender, KeyPressEventArgs e)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (e.KeyChar == (char)(Keys.ControlKey &amp; Keys.A))</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var m_listview = sender as ListView;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (m_listview.Items.Count &gt; 0)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Ctrl+A全选、全消&#39;\u0001&#39;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var m_选择 = m_listview.Items[0].Selected;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foreach (ListViewItem item in m_listview.Items)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; item.Selected = !m_选择;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>这样，在以第一个项的为反向全选择。</p><p><br/></p>]]></description><category>编程</category><comments>http://www.52qu.com/post/38.html#comment</comments><wfw:commentRss>http://www.52qu.com/feed.asp?cmt=38</wfw:commentRss></item><item><title>json字符串转换为Xml对象(方法二)</title><author>wincao@52qu.com (程序员)</author><link>http://www.52qu.com/post/37.html</link><pubDate>Thu, 24 Mar 2022 08:26:08 +0800</pubDate><guid>http://www.52qu.com/post/37.html</guid><description><![CDATA[<p>使用Xml.Linq，方便后期搜索</p><table><tbody><tr class="firstRow"><td width="1509" valign="top" style="word-break: break-all;"><p>using System.Collections.Generic;</p><p style="white-space: normal;">using System.Web.Script.Serialization;</p><p style="white-space: normal;">using System.Xml;</p><p style="white-space: normal;">using System.Xml.Linq;</p><p><br/></p><p>public class ClassJsonToXML<br/></p><p>&nbsp; &nbsp; {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; public static XElement Json2Xml(string sJson)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JavaScriptSerializer oSerializer = new JavaScriptSerializer();</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dictionary&lt;string, object&gt; dict = (Dictionary&lt;string, object&gt;)oSerializer.DeserializeObject(sJson);</p><p><br/></p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; XElement nRoot = new XElement(&quot;root&quot;);</p><p><br/></p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foreach (var item in dict)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var element = new XElement(item.Key);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; KeyValue2Xml(element, item);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nRoot.Add(element);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return nRoot;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p><br/></p><p>&nbsp; &nbsp; &nbsp; &nbsp; private static void KeyValue2Xml(XElement node, KeyValuePair&lt;string, object&gt; Source)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; object kValue = Source.Value;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (kValue == null)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //按值类型跳转</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (kValue.GetType() == typeof(Dictionary&lt;string, object&gt;))</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //类型是字幕</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foreach (KeyValuePair&lt;string, object&gt; item in kValue as Dictionary&lt;string, object&gt;)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var element = new XElement(item.Key); //node.OwnerDocument.CreateElement(item.Key);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; KeyValue2Xml(element, item);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; node.Add(element);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else if (kValue.GetType() == typeof(object[]))</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //类型是数组</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; object[] o = kValue as object[];</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int i = 0; i &lt; o.Length; i++)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var xitem = new XElement(node.Name);//node.OwnerDocument.CreateElement(&quot;Item&quot;);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; KeyValuePair&lt;string, object&gt; item = new KeyValuePair&lt;string, object&gt;(&quot;Item&quot;, o[i]);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; KeyValue2Xml(xitem, item);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; node.Add(xitem);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //类型是值</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //var text = new XElement(kValue.ToString()); //node.OwnerDocument.CreateTextNode(kValue.ToString());</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //node.Add(text);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; node.Value = kValue.ToString();</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; }</p></td></tr></tbody></table><p><br/></p>]]></description><category>编程</category><comments>http://www.52qu.com/post/37.html#comment</comments><wfw:commentRss>http://www.52qu.com/feed.asp?cmt=37</wfw:commentRss></item></channel></rss>
