我可以将表示布尔值的字符串(例如,'true','false')转换为JavaScript中的内部类型吗?
我有一个隐藏的HTML格式,根据用户在列表中的选择进行更新.此表单包含一些表示布尔值的字段,并使用内部布尔值进行动态填充.但是,一旦将此值放入隐藏的输入字段,它就会变成一个字符串.
我可以找到确定字段的布尔值的唯一方法,一旦将其转换为字符串,就要依赖于字符串表示的字面值.
var myValue = document.myForm.IS_TRUE.value;
var isTrueSet = myValue == 'true';
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来实现这一目标?
我无法将boolean值传递给我的指令.
这是我的HMTL:
<city-zip city="clientCity" zip="clientZip" requiredParam="'true'"></city-zip>
Run Code Online (Sandbox Code Playgroud)
指令:
.directive('cityZip', function() {
return {
restrict: 'E',
templateUrl: '../templates/templateCityZip.html',
scope: {
city: '=',
zip: '='
},
controller: function($scope) {}
}
});
Run Code Online (Sandbox Code Playgroud)
任何帮助将非常感激.
alert(x)是假的.但由于某种原因,它不会进入if语句?有任何想法吗?
HTML
@{bool x = false;
foreach (var c in Model.Cleaner.TimeConfirmations.Where(l => l.date.ToShortDateString() == DateTime.Now.ToShortDateString() || l.date.ToShortDateString() == DateTime.Now.AddDays(1).ToShortDateString()))
{
x = true;
}
<span class="ifAvailable" data-confirmationchecker="@x" value="15">@x</span>
}
Run Code Online (Sandbox Code Playgroud)
jQuery的
var x = $(".ifAvailable").data('confirmationchecker')
alert(x);
if ( x == false) {
alert("hi")
}
Run Code Online (Sandbox Code Playgroud)