Evan Zou

Welcome to my blog.

Javascript follower.


Hi, I am Evan, nice to meet you all.

React 单一Input回车触发表单提交事件 踩坑

当表单内只有一个input输入框时,即使表单没有submit按钮,在输入框内按回车就会触发表单的提交事件。

会触发submt

<form id="form1" method="POST">
    <p>Does submit:</p>
    <input type="text"/>
</form>

不会触发submit

<form id="form2" method="POST">
    <p>Does <strong>not</strong> submit:</p>
    <input type="text"/>
    <input type="text"/>
</form>
解决办法:
  1. 若表单只有一个输入框,可以不包含在form元素里。
  2. 再添加一个输入框,并加上display: none的属性。
<form id="form2" method="POST">
    <p>Does <strong>not</strong> submit:</p>
    <input type="text"/>
    <input type="text" style= />
</form>
最近的文章

JS this的用法

关键词:JavaScript this前言本文总结了几类JavaScript中this的用法,同大家一起分享。1. object.function()function中的this指向的是object。2. New Function() 构造函数Function()中的this只想的是正在创建的新对象。3. function() 和匿名函数this指向的是window。4. xxx.prototype.function()function 中的this只想的是将来调用的点前的对象。…

JS继续阅读
更早的文章

CSS IE浏览器自带的清除按钮

最近在项目中遇到了一个浏览器自带样式的问题,在IE浏览器中,Input输入框会自带清除按钮,会与项目中写好的清除按钮发生冲突。解决办法:给Input添加以下样式:::-ms-clear { width : 0; height: 0;}…

CSS IE继续阅读