icheck (获取值)

本文介绍了一个使用iCheck插件定制多选框与单选框样式的示例。通过jQuery与iCheck结合,实现了自定义样式的多选与单选按钮,并展示了如何通过JavaScript获取这些按钮的状态和值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="https://cdn.bootcss.com/iCheck/1.0.2/skins/all.css">
</head>
<style>
    .apps {
        width: 300px;
        margin: auto;
        height: 300px;
        margin-top: 100px;
        border: 1px saddlebrown solid;
    }
</style>

<body>
    <div class="apps">
        <div class="checkeds">
            <input type="checkbox" name="str" id="" class="Red" value="21">21
            <input type="checkbox" name="str" id="" class="Red" value="22">22
            <input type="checkbox" name="str" id="" class="Red" value="23">23
        </div>
        <div class="radiosw">
            <input type="radio" name="sex" id="" class="Red" value="11">11
            <input type="radio" name="sex" id="" class="Red" value="22">22
            <input type="radio" name="sex" id="" class="Red" value="33">33
        </div>
        <button onClick="tags()">dhf</button>
    </div>

    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
    <script src="https://cdn.bootcss.com/iCheck/1.0.2/icheck.js"></script>

    <script>


        // 初始化icheck 多选框与单选框的样式
        $(document).ready(function () {
            $('input').iCheck({
                checkboxClass: 'icheckbox_flat-red',  // 注意square和blue的对应关系
                radioClass: 'iradio_flat-red'
            });
        });

        function tags() {

            // iCheck多选框获取值
            var arrchechbox = []
            $(".checkeds div.checked").each(function (index) {
                arrchechbox.push($(this).find("input").val())
            })

            // iCheck 单选框获取值
            console.log("多选框数组的数据是" + arrchechbox)
            if ($(".radiosw div").hasClass("checked")) {
                console.log("单选框数组的数据是"+$(".radiosw div.checked").find("input").val())
            }
            
        }

    </script>
</body>

</html>

### C# 中通过 'Check' 取值的方法 在 C# 编程中,“check”通常指的是某种验证逻辑或者状态检测操作。例如,可以通过 `CheckBox` 控件的状态来取布尔值,或者通过其他条件判断语句完成特定的任务。 #### 使用 CheckBox 控件取值 当使用 Windows Forms 或 WPF 应用程序中的 `CheckBox` 控件时,可以通过访问其 `Checked` 属性来取当前选中状态: ```csharp // 假设有一个名为 checkBox1 的控件 bool isChecked = checkBox1.Checked; if (isChecked) { Console.WriteLine("Checkbox is checked."); } else { Console.WriteLine("Checkbox is not checked."); } ``` 上述代码展示了如何读取 `CheckBox` 的选中状态并基于该状态执行不同的逻辑[^3]。 #### 自定义 Check 方法实现 如果 “check” 是指自定义的校验逻辑,则可以根据具体需求编写函数。例如,检查某个字符串是否为空或满足某些条件: ```csharp public bool IsStringValid(string input) { if (string.IsNullOrEmpty(input)) { return false; } // 添加更多复杂的校验逻辑 return true; } // 调用示例 string userInput = "example"; bool isValid = IsStringValid(userInput); Console.WriteLine($"Is the string valid? {isValid}"); ``` 此代码片段展示了一个简单的字符串有效性校验方法,并返回布尔类型的校验结果[^4]。 #### 结合事件处理机制 对于动态交互场景(如按钮点击触发校验),可以结合事件处理器实现更复杂的功能。例如,在用户更改下拉框选项时显示提示消息: ```csharp private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { ComboBox cb = sender as ComboBox; if (cb != null && !string.IsNullOrEmpty(cb.SelectedItem?.ToString())) { MessageBox.Show($"Selected item: {cb.SelectedItem.ToString()}"); } } ``` 这里利用了组合框的选择改变事件来进行即时反馈[^2]。 --- ### 总结 无论是直接从 UI 组件提取状态还是构建独立的业务校验流程,都可以灵活运用各种工具和技术达成目标。以上介绍了几种常见的实践模式供参考。 问题
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值