简体   繁体   English

为什么我的单选按钮没有。检查比较有效吗?

[英]Why aren't my radio button.checked comparisons working?

I have three radio buttons that I am working with. 我有三个单选按钮,我正在使用它。 No matter which one I select it seems to default to the first one. 无论我选择哪一个,它似乎默认为第一个。 It's working in regards to actually assigning a value, but the second radio button doesn't seem to be working. 它在实际分配值方面有效,但第二个单选按钮似乎不起作用。

if ($radDB1.Checked = $true){
    $database = 'EXDB01_005'
}
if($radDB2.Checked = $true){
    $database = 'EXDB02_005'
}
if ($radDB5.Checked = $true){
    $database = 'EXDB01_005'
}

They are placed inside a groupbox, which I tried to access here: 它们放在一个组框中,我试图在这里访问:

switch ($grpEXDatabase)
{
    $radDB1.Checked { $database = 'EXDB01_005' }
    $radDB2.Checked { $database = 'EXDB02_005' }
    $radDB5.Checked { $database = 'EXDB01_005' }
}

This did not work. 这没用。 Anyone know what's going on with this? 有谁知道这是怎么回事?

if ($radDB1.Checked -eq $true){
    $database = 'EXDB01_005'
}
if($radDB2.Checked -eq $true){
    $database = 'EXDB02_005'
}
if ($radDB5.Checked -eq $true){
    $database = 'EXDB01_005'
}

The problem with your code is that you're using "=" instead of "-eq" in your if statement. 你的代码的问题是你在if语句中使用“=”而不是“-eq”。 The above should work for checking the value. 以上应该用于检查值。 Otherwise using "=" assigns a value, it doesn't compare it. 否则使用“=”指定一个值,它不会比较它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM