标签: checkbox

控制 Material UI 中的多个复选框

我有一个带有几个复选框的下拉菜单,我试图在每个复选框上添加 onClick 事件。但是当我选中其中一个复选框时,所有复选框都会被选中。这就是我尝试做的:

const [isChecked, setIsChecked] = React.useState(false);

const isCheckboxChecked = () => {
    setIsChecked(isChecked ? false : true)
}

return menuItems.map((item, index) => (
        <React.Fragment>
            <MenuItem
                value={item.value}
                selected={item.value === value}
                key={index}
            >
                <Checkbox
                    key={index}
                    checked={isChecked}
                    onClick={() => isCheckboxChecked()}
                >
                    <Label>{item.label}</Label>
                </Checkbox>
            </MenuItem>
            {index === 2 || index === 3 ? <hr /> : null}
        </React.Fragment>
    ));
Run Code Online (Sandbox Code Playgroud)

据我了解,所有复选框都使用相同的状态isChecked,我想知道如何使它们独立。

checkbox reactjs material-ui

0
推荐指数
1
解决办法
1万
查看次数

在 Delphi 中获取 TCheckbox 的总大小,包括框和文本

我想获得TCheckbox的总大小,包括Delphi中的框和文本。我查看了Delphi FMX TCheckbox/TRadiobutton Autosize上的文章,但似乎 TCheckbox 没有 Canvas 属性,因此代码不适合它。

更新

让我解释一下为什么我需要知道这一点。在我的一些复选框中,我需要放置与复选框相关的 spinedit。例如,在“文件大小大于”###“字节”复选框中,其中 ### 是旋转编辑。

由于复选框不支持自动调整大小,一种方法是放大复选框以容纳所有文本。然后将旋转编辑放在最后一个可见字符之后。

这对于单一语言来说很好,但是,为了支持多语言,某些语言会比其他语言长得多。

在这种情况下,我可以选择:

  1. 计算checkbxo可见部分的大小。

或者

  1. 在最后一个可见字符和旋转编辑之间保留一些空格。

方法 2 不太好,因为对于某些语言,复选框和旋转编辑之间会有很大的距离。

更新2

还有一个问题,我尝试对按钮执行相同的操作,如下所示:

var
  bmp: TBitmap;
  size: TSize;
  width: Integer;
begin
  Checkbox1.Caption := Edit3.Text;
  Button3.Caption := Edit3.Text;

  bmp := TBitmap.Create;
  try
    bmp.SetSize(CheckBox1.Width, CheckBox1.Height);
    bmp.Canvas.Font := CheckBox1.Font;
    size := bmp.Canvas.TextExtent(CheckBox1.Caption);
    Width := bmp.Canvas.TextWidth(Checkbox1.Caption);
    CheckBox1.Width := size.cx + 20;
    button3.Width := size.cx;
    SpinEdit1.Left := Checkbox1.Left + Checkbox1.Width + 5;
  finally
    bmp.Free;
  end;
end;
Run Code Online (Sandbox Code Playgroud)

由于按钮没有任何框,因此我使用 size.cx 而不是添加一些值。然而,在我的测试中,实际上文本宽度不正确,这使得按钮无法容纳整个文本,如下所示:

在此输入图像描述

delphi size checkbox

0
推荐指数
1
解决办法
1034
查看次数

Google chrome 通过 Javascript 或控制台选择所有复选框

我在以下 google chrome 页面上:chrome://history/?q=a

我有一个结果列表,我想确保通过浏览器控制台选择所有复选框。

我已经尝试过这些方法,从这里获取提示,但它似乎不起作用:

[].forEach.call( document.querySelectorAll('input[type="checkbox"]'),function(el){
       el.checked=true;
     }
);
Run Code Online (Sandbox Code Playgroud)
[].forEach.call( document.querySelectorAll('cr-checkbox#checkbox.no-label'),function(el){
       el.checked=true;
     }
);
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

谁能帮我吗?

html javascript checkbox google-chrome dom-events

0
推荐指数
1
解决办法
1510
查看次数

cypress如何检查子复选框是否被选中

当我展开包含复选框列表的复选框父级时,想要循环所有复选框以确保只选择其中的几个:

//expand parent
// select checkbox1
cy.get('[aria-label="checkbox1"]').check({ force: true });
// select checkbox 5
cy.get('[aria-label="checkbox5"]').check({ force: true });

//close then expand again 
Run Code Online (Sandbox Code Playgroud)

问题:如何轻松循环父级下的所有复选框以仅检查 checkbox1 和 5(按名称)是否被选中?

checkbox cypress

0
推荐指数
1
解决办法
349
查看次数

选择复选框立即回显提交按钮

什么是代码,如果我有复选框,并选择它(没有任何提交按钮)显示我提交按钮

<html>
<head>
<title>test</title>
<form method="post">
<?php
//what will be the code here?
?>
<input type='checkbox' name='cb'>
</form>
</html>
Run Code Online (Sandbox Code Playgroud)

javascript php checkbox post submit

-1
推荐指数
1
解决办法
910
查看次数

如何在PHP中获取复选框值

可能重复:
从复选框中检索值

在以下脚本中,我只能返回复选框的最后一个选定值.如何返回其余值以进行验证.

HTML表单

Qualification: <input type="checkbox" name="qual" value="10" /> 10th Std
<input type="checkbox" name="qual" value="12" /> 12th Std
<input type="checkbox" name="qual" value="grad" /> Graduation
Run Code Online (Sandbox Code Playgroud)

PHP代码

 $qual = array();
 $qual = $_GET['qual'];

 print_r ($qual);
Run Code Online (Sandbox Code Playgroud)

html php forms checkbox

-1
推荐指数
1
解决办法
2万
查看次数

通过Checkboxes PHP循环

我想插入一个复选框是否正在选择MySQL,只需在与该值对应的列中添加1或0即可.我遇到了0的问题,详情如下.

以下是复选框的示例

<input type='checkbox' name='class[]' value='mathhl' id="mathhl">
Run Code Online (Sandbox Code Playgroud)

为简单起见,我加了这个

$classes = $_POST["class"];
Run Code Online (Sandbox Code Playgroud)

这是检查复选框值的foreach循环.

foreach($classes as $value) {
    if (!isset($value)) {
        $value = 0;
    }
    else {
        $value = 1;
    }
    echo $value;
}
Run Code Online (Sandbox Code Playgroud)

出于某种原因,它只返回1,但不返回0!我是PHP的新手,所以我想知道我到底哪里出错了,谢谢!

php checkbox loops

-1
推荐指数
1
解决办法
2459
查看次数

Jquery - 如何检查所有复选框是否未选中?

出于某种原因我的代码不起作用?!我需要检查复选框,如果所有都是"未选中",则启用隐藏字段并将值发送到db,这样我就可以确定未选中复选框.

问题1:为什么我的jquery代码不起作用?

问题2:我需要将已检查或未检查的值记录到DB.我的计划是检查是否在php中没有选中.这是一个好习惯吗?

HTML

<tr class="more_info">
        <th valign="top">Other options:</th>
        {foreach from=$HTML_cOPTIONS key=dbname item=optname}
            {if ! empty($CARINFO[car].{$dbname})}
                <td><input type="checkbox" id="forced_checkbox" name="c_options[]" value="{$dbname}" checked/> {$optname} </br></td>
            {else}
                <td><input type="checkbox" id="forced_checkbox" name="c_options[]" value="{$dbname}"/> {$optname} </br></td>
            {/if}
        {/foreach}
        <input type="hidden" id="forceSendCheckBox" name="c_options[]" value="nocheckboxes"/>
        <input type="button" value="Check" id="check" />
    </tr>
Run Code Online (Sandbox Code Playgroud)

jQuery的

$('#check').bind('click',function()
{
    if ($('#forced_checkbox').filter(':not(:checked)').length == 0) {
        console.log('at least one checked');
        $("#forceSendCheckBox").prop('disabled',true);//do not send this field to DB
    } else {
        console.log('nothing checked');
        $("#forceSendCheckBox").prop('disabled',false);//send empty checkboxes
    }
});
Run Code Online (Sandbox Code Playgroud)

UPDATE

这是一个小提琴,它似乎仍然被打破.: - / …

javascript php checkbox jquery smarty

-1
推荐指数
1
解决办法
5508
查看次数

Android:勾选复选框

在我的Android应用程序中,我想定义一个应标记为选中的复选框.任何人都可以解释如何做到这一点?

Thanx提前

java checkbox android

-1
推荐指数
1
解决办法
1001
查看次数

c#取消选中时删除项目复选框

当我选中复选框列表中的复选框时,checkbox.text将添加到列表框中.但是当我取消选中该复选框时,checkbox.text将从列表框中删除.但问题是我不知道如何从列表框中删除所选项目.

[按此处查看图片] [2] <br>

例如,当我选中checkbox1,checkbox2,checkbox3时,列表框将显示
checkbox1 checkbox2 checkbox3

但是,当我取消选中复选框时,我仍然坚持在这里.救命 !!

这是我的代码:

private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
    if (checkBox1.Checked) listBox1.Items.Add(checkBox1.Text);

}

private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
    if (checkBox2.Checked) listBox1.Items.Add(checkBox2.Text);
}

private void checkBox3_CheckedChanged(object sender, EventArgs e)
{
    if (checkBox3.Checked) listBox1.Items.Add(checkBox3.Text);
}

private void checkBox4_CheckedChanged(object sender, EventArgs e)
{
    if (checkBox4.Checked) listBox1.Items.Add(checkBox4.Text);
}
Run Code Online (Sandbox Code Playgroud)

.net c# checkbox checkboxlist winforms

-1
推荐指数
1
解决办法
3710
查看次数