Home  >  Article  >  Web Front-end  >  Can the value of a form element be boolean? _html/css_WEB-ITnose

Can the value of a form element be boolean? _html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:12:511435browse

For example, in the following code

<form name="myform>    <input name="para1" type="hidden" value="false" /></form>


I found that the value false of para here is a string. Is there any way to turn this value into a Boolean value?


Reply to discussion (solution)

var x = document.getElementsByName('para1')[0].value;x = (x === 'false' ? false : true);alert(x);

JScript code
var x = document.getElementsByName('para1 ')[0].value;
x = (x === 'false' ? false : true);
alert(x);

Thank you T5500, I have tried this method , the result proves that even if a Boolean value false is assigned to It is troublesome to define another variable and use if statement to judge. I don’t know if there is any other way

The attribute values ​​of DOM are all strings.

Convert it according to your own needs


The attribute values ​​of DOM are all strings.

Convert it according to your needs


That’s it, thank you~

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn