简体   繁体   English

带按钮的表格,用于移除托架内的托架和文本

[英]Form with Button to Remove Brackets and Text Inside Brackets

I'd like to know how to set up this function to target text in the input form 'STOCK1'. 我想知道如何设置此函数以在输入形式'STOCK1'中定位文本。

Javascript as it stands: 现在的Javascript:

function removeBrackets(element) {
document.body.innerHTML = element.replace(/\[[^\]]+\]/g, '__');
}

HTML as it stands: HTML现状:

<button onclick="javascript:removeBrackets(element)">Remove Brackets and Text Inside Brackets</button>

<input type="text" name="STOCK1" id="STOCK1" placeholder="Place text here..." />

Please help me to understand how this should work! 请帮助我理解这应该如何工作! Many thanks! 非常感谢!

Pass document.getElementById('STOCK1') to removeBrackets call, set .value of element instead of setting document.body.innerHTML . document.getElementById('STOCK1')传递给removeBrackets调用,设置element .value而不是设置document.body.innerHTML Note, you can alternatively use RegExp /\\[.*\\]/g . 注意,您也可以使用RegExp /\\[.*\\]/g 。*] / /\\[.*\\]/g

 <script> function removeBrackets(element) { element.value = element.value.replace(/\\[.*\\]/g, '__'); } </script> <button onclick="removeBrackets(document.getElementById('STOCK1'))">Remove Brackets and Text Inside Brackets</button> <input type="text" name="STOCK1" id="STOCK1" placeholder="Place text here..." /> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM