按钮单击时jquery中的输入值为空白 [英] input value blank in jquery on button click

查看:64
本文介绍了按钮单击时jquery中的输入值为空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi


i希望在文本框内显示价值而不是标签





每个人都表现出像



用户名:< input type =textname =loginhere/>



我想展示像



< input type =textname =loginherevalue =Username/>



点击输入后,值显示消失,输入未点击,点击按钮,

如果输入值则检查jquery,否则显示alert

hi
i want to show value inside textbox and not a label


Everybody shows like

Username : <input type="text" name="loginhere" />

I want to show like

<input type="text" name="loginhere" value="Username" />

when input clicked , the value show disappear , and when input not clicked, and button clicked,
check in jquery if value entered, else show alert

推荐答案

你可以使用HTML5和jQuery来完成它。请检查以下代码



you can do it using HTML5 and jQuery. Please check following code

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication2.WebForm2" EnableViewState="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
   <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
   <script type="text/javascript">
       function CheckValue() {
           var userName =


#userName)。val ();
if (userName == ' '
{
alert(' 用户名为空') ;
}
else
{
alert(userName);
}
}
< / script >
< / head >
< 正文 >
< < span class =code-leadattribute> form id = form1 runat = server >
< div >
< input type = text id = userName name = userName 占位符 = 用户名 > < br >
< asp:按钮 ID = btnSubmit runat = server 文字 < span class =code-keyword> = 提交 OnClientClick = CheckValue() / >
< / div > ;

< / form >
< / body >
< / html >
("#userName").val(); if (userName == '') { alert('user Name is empty'); } else { alert(userName); } } </script> </head> <body> <form id="form1" runat="server"> <div> <input type="text" id="userName" name="userName" placeholder="Username"><br> <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClientClick="CheckValue()" /> </div> </form> </body> </html>


这篇关于按钮单击时jquery中的输入值为空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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