bootstrap使用中遇到的坑

本文介绍在使用Bootstrap框架时如何解决表单form-group内select标签动态赋值的问题,并提供了具体的JavaScript实现方法。

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

一、例如: 

<div class="form-group">
                        <label class="control-label col-lg-3">用户类型<font style="color:red;">*</font></label>
                        <div class="col-lg-9">
                            <select id="UserTypeID" name="UserTypeID" class="form-control" autocomplete="off"></select>

                        </div><!-- /.col -->
 </div><!-- /form-group -->

在bootstrap中会遇到这么一个问题,一个form-group里面含有一个select标签,在赋值时进行动态赋值:

function EditUser(xuhao) {
            $("#form_SaveUser").get(0).reset(); //清空form
            $("#form_SaveUser").parsley().reset(); //清空校验信息
            var n = xuhao - 1;
            $("#form_SaveUser#UserTypeID").val(UserList[n].UserTypeID);
                //这里会有一个弹出口
            $('#User-modal').modal('show');
            if (UserList[n].UserType == "Administrator") {
                $("#form_SaveUser #UserTypeID").find("option[value = '管理员']").attr("selected", true);
            } else if (UserList[n].UserType == "General") {
                $("#form_SaveUser #UserTypeID").find("option[value = '普通用户']").attr("selected", true);
            } else if (UserList[n].UserType == "root") {
                $("#form_SaveUser #UserTypeID").find("option[value = '超级用户']").attr("selected", true);
            } else if (UserList[n].UserType == "Manager") {
                $("#form_SaveUser #UserTypeID").find("option[value = '负责人']").attr("selected", true);
            }
        }    

在弹出时会将form表单的值清空,所以要在弹出之后将值赋上去,这样就不会受到影响。

转载于:https://www.cnblogs.com/baojiao/p/9289599.html

(venv) yyl@yyl-virtual-machine:~/PycharmProjects/ros2/chapt3/topic_ws/src$ ros2 run demo_python_topic novel_sub_node Traceback (most recent call last): File "/home/yyl/PycharmProjects/ros2/chapt3/topic_ws/src/install/demo_python_topic/lib/demo_python_topic/novel_sub_node", line 33, in <module> sys.exit(load_entry_point('demo-python-topic==0.0.0', 'console_scripts', 'novel_sub_node')()) File "/home/yyl/PycharmProjects/ros2/chapt3/topic_ws/src/install/demo_python_topic/lib/demo_python_topic/novel_sub_node", line 25, in importlib_load_entry_point return next(matches).load() File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 171, in load module = import_module(match.group('module')) File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1050, in _gcd_import File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 688, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 883, in exec_module File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "/home/yyl/PycharmProjects/ros2/chapt3/topic_ws/src/install/demo_python_topic/lib/python3.10/site-packages/demo_python_topic/novel_sub_node.py", line 3, in <module> import espeakng ModuleNotFoundError: No module named 'espeakng' [ros2run]: Process exited with failure 1
最新发布
06-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值