JS案例 顯示隱藏文字框內容

2021-10-07 22:56:03 字數 851 閱讀 5280

<

!doctype html>

"en"

>

"utf-8"

>

"viewport" content=

"width=device-width, initial-scale=1.0"

>

"x-ua-compatible" content=

"ie=edge"

>

document<

/title>

input

<

/style>

<

/head>

"text" value=

"手機"

>

// 1.獲取元素

var text = document.

queryselector

('input');

// 2.註冊事件 獲得焦點事件 onfocus

text.

onfocus

=function()

// 獲得焦點需要把文字框裡面的文字顏色變黑

this

.style.color =

'#333';}

// 3. 註冊事件 失去焦點事件 onblur

text.

onblur

=function()

// 失去焦點需要把文字框裡面的文字顏色變淺色

this

.style.color =

'#999';}

<

/script>

<

/body>

<

/html>

顯示隱藏文字內容 2020 11 20

自學js,錯誤案例 value可得到屬性值或者更改屬性值 判斷value值是否為空,所以用 doctype html content type content text html charset utf 8 input style head 1 value可得到屬性值或者更改屬性值 text val...

input實時監聽文字框內容

在做搜尋時經常會用到我們需要監聽input input on keydown function 因為keydown事件處理函式中立即獲取文字框中的內容,通常會有乙個字元的偏差 他是在鍵盤按下瞬間觸發所以基本不用這個方法,html5新增屬性input 非常nice input on input fun...

html的判斷文字框內容舉例

在很多情況下,我們都需要登陸 註冊等,如果輸入的東西不符合要求,那麼就會無法提交資料內容。我們這次的介面設計裡面用到了這個,覺得有用拿來看看。序號 這裡的pattern裡面是正規表示式規則,是在text裡面輸入符合規則的資料,這個簡單的就是輸入的資料必須是0到9數字。管理者 儲存這個是用到了jsp,...