admin管理员组

文章数量:1399839

Assume I have a radio button and it returns value as -1, -2, 3 or 4 etc. what is the type of value it throws? Is it string or integer? eg.:

<input type="radio" name="case-type" class="ButtonState" id="Electrician" value="-1" />
<label class="Button" for="Electrician"> Electrician </label>
<input type="radio" name="case-type" class="ButtonState" id="Plumber" value="-2" />

what does is the type of -1 or -2 here, should i use an integer variable to bind those values in my code or should i bind the variables in string variables?

<label class="Button" for="Plumber">Plumber</label>

Assume I have a radio button and it returns value as -1, -2, 3 or 4 etc. what is the type of value it throws? Is it string or integer? eg.:

<input type="radio" name="case-type" class="ButtonState" id="Electrician" value="-1" />
<label class="Button" for="Electrician"> Electrician </label>
<input type="radio" name="case-type" class="ButtonState" id="Plumber" value="-2" />

what does is the type of -1 or -2 here, should i use an integer variable to bind those values in my code or should i bind the variables in string variables?

<label class="Button" for="Plumber">Plumber</label>
Share Improve this question edited Aug 10, 2018 at 14:25 k.vincent 4,1638 gold badges43 silver badges85 bronze badges asked Aug 10, 2018 at 13:55 faizefaize 591 silver badge12 bronze badges 2
  • 1 It is a string. – Jonas Wilms Commented Aug 10, 2018 at 13:56
  • in your browser console: typeof document.querySelector('input[name="case-type"]').value would equal "string" – James LeClair Commented Aug 10, 2018 at 14:00
Add a ment  | 

1 Answer 1

Reset to default 10

The value of an input element is always a string (spec | MDN).

On modern browsers, specialized input elements (type="number", type="date") have additional properties (valueAsNumber, valueAsDate), but value is always a string.

本文标签: javascriptwhat is the return type of a radio button value is it integer or stringStack Overflow