如何用JavaScript修改输入框值?Chrome开发者工具修改失效求助
I’ve dealt with this exact frustration on Upbit’s trading interface before—those modern front-end frameworks don’t let you just tweak DOM values willy-nilly. Let’s break down why your attempts aren’t sticking and how to actually make it work.
Upbit uses a framework like React to power its interface, where the input’s displayed value is tied to the framework’s internal state, not just the raw DOM value property. When you edit the value in DevTools, you’re only updating what’s visible in the DOM, not the underlying state the app uses to process your input. On top of that, there are likely input or change event listeners that validate or sync the value—these don’t fire automatically when you manually edit the DOM.
The best way to get the app to recognize your change is to mimic exactly what a human user does: set the value, then trigger the events the framework is listening for. Here’s how to do it in Chrome DevTools’ Console:
- Grab the input’s selector: Go to the Elements panel, find the input box (e.g., price or quantity for KRW-BTC), right-click it, and select
Copy > Copy selectorto get an accurate CSS selector. - Run this script in the Console:
// Replace with your copied selector (e.g., 'input[placeholder="가격 입력"]') const inputElement = document.querySelector('YOUR_COPIED_SELECTOR'); if (inputElement) { // Set your desired value (e.g., '50000000' for 50M KRW) inputElement.value = 'YOUR_TARGET_VALUE'; // Trigger the input event (React and similar frameworks listen for this to sync state) inputElement.dispatchEvent(new Event('input', { bubbles: true })); // Optional: Trigger the change event if the app uses it for final validation inputElement.dispatchEvent(new Event('change', { bubbles: true })); }
This should sync your value to the app’s internal state, making it recognize the change just like if you typed it manually.
If the first method doesn’t work (rare, but possible), you can directly edit the framework’s state. For React-based sites like Upbit:
- Install the React DevTools extension for Chrome.
- Open DevTools, switch to the
Componentstab, and find the component that controls the input (look for state variables likepriceorquantity). - Edit the state value directly in the React DevTools—this will automatically update the input and the app’s state.
Note: This method is less reliable over time, since Upbit might change their component structure with updates.
- Upbit has anti-automation safeguards. Repeatedly using scripts to modify inputs could lead to account restrictions, so only use this for learning purposes.
- Always test with non-transactional changes first to avoid accidental trades!
内容的提问来源于stack exchange,提问作者PEPE BIT

