本文介绍了如何在文本框中键入文本时显示和消失按钮。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, i希望出现并消失按钮,同时在文本框中输入文字。 不在页面中执行任何其他功能 - 加载或刷新页面只需键入按钮应显示的文本,如果文本框应为空,则按钮消失。为此任务提供帮助。hi to all, i want to appear and disappear the button,while typing the text in text-box.don't do any other functionality in page-load or refresh the page just type the text the button should appear,if the text box should empty then button disappear.Kindly help for this task.推荐答案window.onload = function () { var txt = document.getElementById("<%= yourTxt.ClientID %>"); var btn = document.getElementById("<%= yourBtn.ClientID %>"); if (txt.value === "") { btn.style.visibility = "hidden"; // when the window is loaded, hide the button if the textbox is empty } txt.onkeyup = function () { if (txt.value !== "") { btn.style.visibility = "visible"; } else { btn.style.visibility = "hidden"; } };}; 当您的页面加载时,它会检查文本框是否为空,如果是,则会隐藏按钮。 在 onkeyup 时,代码会检查文本框中是否有文字。如果是,则显示按钮,如果不是,则隐藏按钮。When your page is loaded, it checks whether the textbox is empty, and if it is, it hides the button.At onkeyup, the code checks whether there's text in the textbox. If yes, it shows the button, if no, it hides the button.function EnableDisableButton(sender, target) { if (sender.value.length > 0) document.getElementById('<%= btnReset.ClientID %>').disabled = false; else document.getElementById('<%= btnReset.ClientID %>').disabled = true; } 这篇关于如何在文本框中键入文本时显示和消失按钮。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-23 01:14