js——if judgment (operate only when it is an empty string, use congruence)

Case Description

We often judge whether there is content to enter in the input box, and it will prompt when there is no input content and click submit. The same goes for drop-down boxes.
Previous judgment:

<input type="text" placeholder="请输入员工名称" v-model="names">
if (!this.names) {
    
    
	//提示:('请输入姓名')
	return
}

Drop-down box selection:
insert image description here
Default status:' '
But the following writing is not allowed, because disabled is 0, !0 is equal to true, and he will also prompt, at this time, it needs to be judged by congruence.

if (!this.status) {
    
    
	//提示:('请选择状态')
	return
}

Congruent judgment

if (this.status === '') {
    
    
	//提示('请选择状态')
	return
}

Guess you like

Origin blog.csdn.net/xulihua_75/article/details/130316295