課程
/前端開發(fā)
/jQuery
/jQuery基礎(chǔ)課程
請(qǐng)師兄指點(diǎn)
2016-05-13
源自:jQuery基礎(chǔ)課程 6-8
正在回答
這樣寫
?$(function(){
? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? $("#txtest").focus(function(){
? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ? $("div").html("請(qǐng)輸入您的姓名");
? ? ? ? ? ? ? ? })
? ? ? ? ? ? ? ? $("#txtest").keydown(function(){
? ? ? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ? ? ? if($(this).val().length!=0)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? $("div").css("display","none");
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? });
攻城獅3343388 提問者
記得 ?input里 有個(gè) placeholder(哈哈) 屬性 ? 的效果 ? 好像就是你想要的。
<p>謝謝,三可思密達(dá)</p>
你們這樣改效果不好,應(yīng)該是當(dāng)input得到focus時(shí),并且用戶一旦輸入內(nèi)容,下面的文字就沒了,而不是失去焦點(diǎn)時(shí)消失
<!DOCTYPE?html> <html?xmlns="http://www.w3.org/1999/xhtml"> ????<head> ????????<title>表單中文本框的focus和blur事件</title> ????????<script?src="http://libs.baidu.com/jquery/1.9.0/jquery.js"?type="text/javascript"></script> ????????<link?href="style.css"?rel="stylesheet"?type="text/css"?/> ????</head> ???? ????<body> ????????<h3>表單中文本框的focus和blur事件</h3> ????????<input?id="txtest"?type="text"?value=""?/> ????????<div></div> ???????? ????????<script?type="text/javascript"> ????????????$(function?()?{ ????????????????$("input").bind("focus",?function?()?{ ????????????????????$("div").html("請(qǐng)輸入您的姓名!"); ????????????????}) ????????????????.bind("blur",function?()?{ ????????????????????if?($(this).val().length?==?0){ ????????????????????????$("div").html("你的名稱不能為空!"); ????????????????????}else{ ???????????????????????$("div").html("");? ????????????????????} ????????????????}) ????????????}); ????????</script> ????</body> </html>
就是把html()里面的東西設(shè)置為空,不知道是不是你要的效果。
在blur后面加上判斷語句即可,
.bind("blur", function () {
? ? ? ? ? ? ? ? ? ? if ($(this).val().length== 0)
? ? ? ? ? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ? ? ? ? ? ?$("div").html("你的名稱不能為空!"); ? ? ?
? ? ? ? ? ? ? ? ? ? ? ?}else{
? ? ? ? ? ? ? ? ? ? ? ? ? ?$("div").html("");
? ? ? ? ? ? ? ? ? ? ? ?}
同問。
舉報(bào)
加入課程學(xué)習(xí),有效提高前端開發(fā)速度
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2016-05-14
這樣寫
?$(function(){
? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? $("#txtest").focus(function(){
? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ? $("div").html("請(qǐng)輸入您的姓名");
? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? })
? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? $("#txtest").keydown(function(){
? ? ? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ? ? ? if($(this).val().length!=0)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? $("div").css("display","none");
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? })
? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? });
2016-05-15
記得 ?input里 有個(gè) placeholder(哈哈) 屬性 ? 的效果 ? 好像就是你想要的。
2016-05-14
<p>謝謝,三可思密達(dá)</p>
2016-05-14
你們這樣改效果不好,應(yīng)該是當(dāng)input得到focus時(shí),并且用戶一旦輸入內(nèi)容,下面的文字就沒了,而不是失去焦點(diǎn)時(shí)消失
2016-05-13
就是把html()里面的東西設(shè)置為空,不知道是不是你要的效果。
2016-05-13
在blur后面加上判斷語句即可,
.bind("blur", function () {
? ? ? ? ? ? ? ? ? ? if ($(this).val().length== 0)
? ? ? ? ? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ? ? ? ? ? ?$("div").html("你的名稱不能為空!"); ? ? ?
? ? ? ? ? ? ? ? ? ? ? ?}else{
? ? ? ? ? ? ? ? ? ? ? ? ? ?$("div").html("");
? ? ? ? ? ? ? ? ? ? ? ?}
2016-05-13
同問。