Checkbox 签入/签入HTML复选框中的三元操作
My JavaScript根据布尔值弹出动态HTML,其中一个字段为复选框,如下所示:Checkbox 签入/签入HTML复选框中的三元操作,checkbox,operator-keyword,ternary,Checkbox,Operator Keyword,Ternary,My JavaScript根据布尔值弹出动态HTML,其中一个字段为复选框,如下所示: <input type="checkbox" disabled='true' (bool == true ? "Checked":"undefined") /> 即使布尔值为false,我的复选框始终返回checked。 有没有关于三元运算的建议 而且我刚刚意识到很难为每行复选框都设置id。下面是我的函数当前的样子: 函数fnBuildWebSiteClipHtml(名称、url、id、允许
<input type="checkbox" disabled='true' (bool == true ? "Checked":"undefined") />
即使布尔值为false,我的复选框始终返回checked。
有没有关于三元运算的建议
而且我刚刚意识到很难为每行复选框都设置id。下面是我的函数当前的样子:
函数fnBuildWebSiteClipHtml(名称、url、id、允许删除、使用全屏){
var html=“”+
tdstart+“”+OrionCore.escapeHtml(名称)+”+
tdstart+OrionCore.escapeHtml(url)+“+
tdstart+++
tdstart+++
tdstart+
"" +
"" +
" | " +
"" +
"" +
"" +
"" +
"";
返回html;
}
第8行,我选中了allow_Removing,然后在下面的第8行中选择check for use_full_屏幕,这是我试图让我的复选框跟随的内容。非常感谢您对此提出的任何建议
感谢您已经发布的回复,但我不知道如何在这种情况下满足您的要求。您可能需要它吗
<body onload="(bool ==true) ? document.getElementById('myTernaryCheckBox').setAttribute('checked', 'checked') : false">
<input type="checkbox" disabled id="myTernaryCheckBox"/>
</body>
如何设置bool变量?这两个变量都是从数据库中读取的,另一个函数将它们作为参数传递。我尝试了这一个,但无法适应我的函数。除非我为多行复选框分配id。
<body onload="(bool ==true) ? document.getElementById('myTernaryCheckBox').setAttribute('checked', 'checked') : false">
<input type="checkbox" disabled id="myTernaryCheckBox"/>
</body>