javascript-事件发生时显示文本 [英] javascript-- showing texts when an event occur

查看:91
本文介绍了javascript-事件发生时显示文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

事件发生时如何显示某些文本?
假设我创建了一个表单:
*********************
< form name ="test" id ="form1" runat ="server">
用户名:
#username无效
师资队伍:
#faculty无效
</form>
************************
我必须在用户名或教职员工无效的情况下显示文本,否则必须将其隐藏.

我该如何使用JavaScript?

How to show certain text when an event occurs??
Suppose I''ve created a form:
*********************
<form name="test" id="form1" runat="server">
Username:
#username is invalid
Faculty:
#faculty is invalid
</form>
************************
I''ve to show the texts when the username or faculty is invalid.Otherwise the texts must be hidden.

How can I do this using javascript?? Will anyone provide me some ideas??

推荐答案

您没有描述什么事件,所以:

You did not describe what event, so:

function SomeHandler() {
    /* ... */
    var div = document.getElementById("output");
    if (someCondition)
        div.innerHTML = "username is invalid";
    else if (someOtherCondition)
        div.innerHTML = "faculty is invalid";
    /* ... */
}

<!-- ... -->

<div id="output" />



—SA



—SA


事件

当光标从用户名"移动到密码" 时,必须检查用户名的有效性.如果用户名无效,则文本必须显示为"用户名无效".如何通过 Javascript ??
做到这一点
同样,当光标从密码"移出时,则必须检查密码"的有效性.如果密码无效,则文本必须显示为"密码无效".
Events

When the cursor moves from Username to Password, then the validation of username must be checked. And if the username is invalid, then the text must appear as "Username is invalid". How to do this via Javascript??

Similarly, When the cursor moves from Password, then the validation of Password must be checked. And if the Password is invalid, then the text must appears as "Password is invalid".


这篇关于javascript-事件发生时显示文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆