如何在文本框中键入文本时显示和消失按钮。 [英] how to appear and disappear the button,while typing the text in text-box.
问题描述
大家好,
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.
推荐答案
使用以下JavaScript代码。将其包装在< script>
标记中,并将其放在< head>
标记上:
Use the following JavaScript code. Wrap it in a<script>
tag and place it on your<head>
tag:
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.
试试这个..
1)< a href =http://stackoverflow.com/questions/13158752/fire-event-on-enter-key-press-for-a-textbox>输入键上的火灾事件按下文本框 />
2)在AngularJS中的文本框中按Enter键时触发按钮单击
Try this..
1) Fire event on enter key press for a textbox
2) Trigger a button click when pressing enter in a textbox in AngularJS
function EnableDisableButton(sender, target) {
if (sender.value.length > 0)
document.getElementById('<%= btnReset.ClientID %>').disabled = false;
else
document.getElementById('<%= btnReset.ClientID %>').disabled = true;
}
这篇关于如何在文本框中键入文本时显示和消失按钮。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!