0

我需要在创建复选框后创建一个复选框,并在其中选中属性。我使用百里香在第二个跨度中创建了一个选中的复选框

百里香代码:

<span th:if="${field.fieldtype == 'CHECK'}">
    <input class="check" name="checkbox" type="checkbox"
           th:id="@{${field.value}}"  th:value="${record.id}"/>
</span>
<span th:if="${field.fieldtype == 'CHECK'}">
    <div th:each="prd ,iterStat : ${prdList}" th:remove="tag">
            <div th:if="${field.value}==${prd.Name}" th:remove="tag">
                <!-- <input class="check" name="checkbox" type="checkbox" checked="true"
                    th:id="@{${field.value}}" th:value="${record.id}" /> --> //appends an extra checkbox with already existing one but with checked attr
                <script type="text/javascript">//script code to check the unchecked check box</script>
            </div>
    </div>
 </span>

我生成的 html 代码看起来像这样,

<td>
<span> 
    <input type="checkbox" value="1" id="NAME" name="checkbox" class="check">
</span>
<span>
    <script>
     $(document).ready(function(){
        console.log('checkme');
        $(this).closest('input').find(':checkbox').attr('checked', true);
     });
    </script>
</span>
</td>
<td>
    <span> ..checkbox.. </span>
    <span> ..script.. </span>
</td>
<td>
    <span> ..checkbox.. </span>
    <span>  </span>//in some conditon script not created so leave the checkbox unchecked
</td>
<td>
    <span> ..checkbox.. </span>
    <span> ..script.. </span>
</td>

仅当其中有脚本时,我才需要从第二个跨度中的脚本检查第一个跨度中的复选框..我该怎么做..示例

谢谢..

4

0 回答 0