在文本输入中插入空值 [英] Insert null value into a text input
问题描述
我很确定这是不可能的,但我仍在要求.
I'm pretty sure it's not possible to do this but I'm still asking for it.
用户是否可以将NULL(或未定义)值插入html文本输入中?
Is there a way for a user to insert a null (or an undefined) value into an html text input?
我需要区分一个空值和一个空字符串,我想允许用户将该值设置为单个输入.
I need to distinguish between a null value and an empty string and I would like to allow the user to set this value into a single input.
对于我在网络上看到的内容,此问题的标准解决方案是将文本输入与复选框相匹配,以表明该值是否为null.根据我的理解,该限制与以下事实有关:文本框可以包含一个空字符串,但不能包含一个空值,这就是为什么我认为无法完全按照自己的意愿进行操作.
For what I can see across the web, the standard solution to this problem is to match the text input with a checkbox that tell if the value is null or not. From my understanding, the limitation is linked to the fact that the textbox can hold an empty string but not a null value so that's why I think it's not possible to do exactly what I want.
推荐答案
您不能告诉文本输入具有任何类型的 null
值.根据定义,空复选框的值为空字符串''
.如您所说,最好的方法是有一个复选框,用于切换文本输入的 disabled
属性,从而提供相似的语义.
You can't tell a text input to have any kind of null
value. Empty checkboxes have a value of an empty string ''
by definition. The best way to do it, as you say, is to have a checkbox that toggles the disabled
property of the text input, which gives a similar semantic.
这篇关于在文本输入中插入空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!