Aspnet文本框如何实现全选?文本框全选方法教程
<script>document.addEventListener('DOMContentLoaded',function(){consttxtDemo=document.getElementById('txtDemo');constbtnSelect=document.getElementById('btnSelect');if(txtDemo&&btnSelect){btnSelect.addEventListener('click',function(){txtDemo.select();document.execCommand('copy');//附加复制功能增强体验});}//页面加载自动聚焦示例consttxtAutoFocus=document.getElementById('txtAutoFocus');if(txtAutoFocus){txtAutoFocus.focus();txtAutoFocus.select();}});</script><p>通过JavaScript的<code>select()</code>方法或服务端结合<code>TextBox.Attributes.Add()</code>实现全选功能,核心代码为:</p><pre><code>//JavaScript实现document.getElementById("txtInput").select();//ASP.NET服务端实现(Page_Load中)txtInput.Attributes.Add("onfocus","this.select();");</code></pre><divclass="example-box"><h3>立即体验:</h3><inputtype="text"id="txtDemo"value=https://idctop.com/article/"尝试全选这段文本"class="demo-input">>