input type text,按回車鍵自動提交

2022-01-26 13:17:51 字數 1463 閱讀 4414

1、當form表單中只有乙個時按回車鍵將會自動將表單提交

<

form

id='form1'

action

='a1.jsp'

method

='post'

>

<

input

type

='text'

name

='name'

/>

form

>

view code

再新增乙個按下回車將不會自動提交,但是頁面上顯示乙個不知所云的輸入框挺彆扭,後從網上搜到兩個解決辦法:

1;新增乙個不顯示輸入框,然後回車之後也不會提交:

<

form

id='form1'

action

='a1.jsp'

method

='post'

>

<

input

type

='text'

name

='name'

/>

<

input

style

='display:none'

/>

form

>

view code

2;新增乙個onkeydown事件,然後回車之後也不會顯示:

<

form

id='form1'

action

='a1.jsp'

method

='post'

>

<

input

type

='text'

name

='name'

onkeydown

='if(event.keycode==13)

return false;'

/>

form

>

view code

如果想新增回車事件可以在onkeydown事件中新增判斷提交表單:

<

form

id='form1'

action

='a1.jsp'

method

='post'

>

<

input

style

='display:none'

/>

<

input

type

='text'

name

='name'

onkeydown

='if(event.keycode==13)'

/>

form

>

view code

使input type 「text「不可編輯

readonly 意思是字段為唯讀,使用者可以使用 tab 鍵切換到該字段。使用後文字框不可編輯 選擇文字框不會出現閃爍的游標 可以接收焦點,表單可提交其value值,後台可以接收到傳值。id type text name id readonly value 意思是禁用input 元素 不可編輯 不...

Python 實現「按任意鍵返回」和無回顯輸入

學python 用rpa www.i search.com.cn index.html?from line1 功能描述 在某些應用場景中,需要實現 按任意鍵返回 這樣的功能,在 python 中如果使用內建函式 input 的話必須有個回車鍵才表示輸入結束,不夠完美。在 msvrct 標準庫中,可以...

按位AND和按位OR

description 已知長度為n的兩個位串a和b,求它們的按位and和按位or。input 多組測試資料,每組測試資料第1行輸入位串長度n 0 n 64 第2行輸入n個以空格隔開的取值為0或1的整數表示位串a,第3行輸入n個以空格隔開的取值為0或1的整數表示位串b。output 每組測試資料佔兩...