TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

The code ChatGPT wrote to help with my YC application

3 点作者 magicseth大约 2 年前
I&#x27;m sitting here working on my YC application, and it has character limits.<p>I thought it would be nice to see a live update of character counts, so I asked GPT:<p><i>Write a bit of javascript that I can paste into chrome devtools. Everytime I enter text in an input box, it should show the character count of the current input box in a div in the lower left of the website. When I change to a new input, the counter should reset.</i><p>And it spit out code that worked perfectly.<p>This is a new era of &quot;disposable code&quot; appears when needed, and can be thrown away!<p>here&#x27;s the javascript if you want to try it:<p><pre><code> &#x2F;&#x2F; Select the input fields you want to monitor const inputFields = document.querySelectorAll(&#x27;input[type=&quot;text&quot;]&#x27;); &#x2F;&#x2F; Create a div element to display the character count const characterCountDiv = document.createElement(&#x27;div&#x27;); characterCountDiv.style.position = &#x27;fixed&#x27;; characterCountDiv.style.bottom = &#x27;0&#x27;; characterCountDiv.style.left = &#x27;0&#x27;; characterCountDiv.style.background = &#x27;#fff&#x27;; characterCountDiv.style.padding = &#x27;10px&#x27;; document.body.appendChild(characterCountDiv); &#x2F;&#x2F; Keep track of the current input field being edited let currentInputField = null; &#x2F;&#x2F; Listen for input events on each input field inputFields.forEach((inputField) =&gt; { inputField.addEventListener(&#x27;input&#x27;, () =&gt; { &#x2F;&#x2F; If this is a new input field, reset the character count if (inputField !== currentInputField) { currentInputField = inputField; characterCountDiv.innerText = `Character count: ${inputField.value.length}`; } else { characterCountDiv.innerText = `Character count: ${inputField.value.length}`; } }); });</code></pre>

暂无评论

暂无评论