提问者:小点点

检查是否在wordpress wp-admin中添加了伪元素:before


我正在尝试检查在Wordpress管理新的职位创建页面每当复选框被选中。 但是,wordpress并不是将状态更改为输入字段,而是在输入标记之间添加一个伪元素::before,如下所示:

<label class="selectit"><input value="631" type="checkbox" name="tax_input[property-city][]" id="in-property-city-631">::before</input> ABCDE</label>

这是未选中复选框时的代码:

<label class="selectit">
<input value="631" type="checkbox" name="tax_input[property-city][]" id="in-property-city-631"> ABCDE</label>

有没有任何方法可以在至少检查一个输入时使用Jquery进行检查?


共1个答案

匿名用户

如果只需要验证,则可以使用:checked选择器和该集合中匹配元素的长度

类似于:

null

const hasChecked = !!$(':checkbox[id^="in-property-city"]:checked').length;

console.log(hasChecked)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label class="selectit">
<input value="631" type="checkbox" name="tax_input[property-city][]" id="in-property-city-631"> ABCDE</label>

<label class="selectit">
<input checked value="63" type="checkbox" name="tax_input[property-city][]" id="in-property-city-63"> XYZ</label>