如果输入为空,则在输入中运行功能?

时间:2019-02-28 09:55:23

标签: javascript

无论如何,我可以使用javascript检查输入是否为空,然后运行函数吗?如果可能的话,我希望它包含在输入中。

onChange,有ifEmpty大声笑吗?

2 个答案:

答案 0 :(得分:0)

<input onChange="this.value.trim().length > 0 && myFunction()" />

答案 1 :(得分:0)

尝试一下

function a(e)
{
if(e.value=="")
return false;
else
console.log('there is a value')
}
<input value="" onclick="a(this)">