首页 > 解决方案 > 无法更改单选复选框中的预设选择

问题描述

我真的没有经验。我是一名护理人员,我必须使用包含许多多余字段的冗余表格填写数百个患者表格。

我正在尝试编写一个脚本来预填充一些对大多数患者保持不变的字段,例如“年龄单位”。我们患者的几乎所有年龄都以“年”为单位,但列出的软件字段包括“分钟、小时、天、周、月、年、取消选择等”。该字段是完成报告所必需的,但默认设置为“取消选择”,这将阻止完成报告。

我已按原样附上了代码。我真的不得不用谷歌搜索它是用什么(语言?)写的。首先,我想我可以检查默认元素,检查所需的元素,然后修改值以便检查所需的元素。然后,我尝试使用允许我选择表单字段并修改值的自动填充扩展。我试图将其修改为复选框/收音机。我尝试使用 JavaScript。我大喊。我非常失败。如果有人能指出我正确的方向,我将永远感激不尽。我什至不知道我要修改什么。它是收音机/复选框吗?是按钮吗?是文字吗?

我已经尝试了我虚弱的大脑所能做的一切。

这就是表单中令人讨厌的元素之一的样子。

<div class="radio_checkbox_div_container">
  <table class="table_radio">
    <tbody>
      <tr>
        <td class="td_radio ui-state-highlight"><input type="radio" name="ePatient_16" id="ePatient_16_cancel" value="" checked=""> Cancel Selection </td>
        <td colspan="2"> &nbsp; </td>
      </tr>
      <tr>
        <td class="td_radio td_3col"><input type="radio" class="reg_option" name="ePatient_16" id="ePatient_16_0" value="2516001"> Days </td>
        <td class="td_radio td_3col"><input type="radio" class="reg_option" name="ePatient_16" id="ePatient_16_1" value="2516003"> Hours </td>
        <td class="td_radio td_3col"><input type="radio" class="reg_option" name="ePatient_16" id="ePatient_16_2" value="2516005"> Minutes </td>
      </tr>
      <tr>
        <td class="td_radio td_3col"><input type="radio" class="reg_option" name="ePatient_16" id="ePatient_16_3" value="2516007"> Months </td>
        <td class="td_radio td_3col"><input type="radio" class="reg_option" name="ePatient_16" id="ePatient_16_4" value="2516009"> Years </td>
        <td class="td_radio td_3col"><input type="radio" class="nil_option" name="ePatient_16" id="ePatient_16_5" value="7701001"> Not Applicable </td>
      </tr>
      <tr>
        <td class="td_radio td_3col"><input type="radio" class="nil_option" name="ePatient_16" id="ePatient_16_6" value="7701003"> Not Recorded </td>
      </tr>
    </tbody>
  </table>
</div>

我想修改一些表单字段(都与上面类似),以便我最常用的选择是默认值。

标签: javascriptbootstrap-4

解决方案


你好你好,

我为您创建了一个 jsfiddle,只需复制粘贴 html 标签并替换脚本中的 id 即可选择单选按钮和其他元素

这会给你基本的想法

https://jsfiddle.net/1efx59vn/

<div class="radio_checkbox_div_container"><table class="table_radio"><tbody><tr><td class="td_radio ui-state-highlight"><input type="radio" name="ePatient_16" id="ePatient_16_cancel" value="" > Cancel Selection </td><td colspan="2"> &nbsp; </td></tr>
<script>
$('#ePatient_16_cancel').attr('checked', 'true')
</script>

如我所见,您是新手,对javascript一无所知,因此您很难理解。但是试着理解这个脚本中的一些东西标签 $('#ePatient_16_cancel').attr('checked', 'true')_ePatient_16_cancel_ 是单选按钮的 id,id 表示您的唯一帐号,没有人会拥有,也找到其他元素的 id 并放入$('#')替换带有元素 ID。

所以脚本看起来像这样 $('#ePatient_16_cancel').attr('checked', 'true')

在 chrome 浏览器中打开表单并按 F12 键,导航到控制台选项卡并将脚本粘贴到控制台中,然后按 Enter,这将为您选择单选按钮


推荐阅读