尝试验证我在WordPress的事件日历内创建的自定义字段时出现问题,我在“活动”页面/帖子中有许多自定义字段。它使用标准post-new.php或post.php,我希望能够验证其中一些自定义字段。但是,这些领域没有ID。只列出这样的元素:
<input type="text" name="_ecp_custom_3" value="">
所以我正在尝试这个脚本:
jQuery(document).ready(function($) {
$('#title').attr('required', true);
$("[name='_ecp_custom_3']").attr("required", true);
});
#title一个很好用,但是自定义的一个回来时出错,说:
解析错误:意外的令牌_ecp_custom_3
那么如何使用name元素而不是ID来验证此字段?
我尝试了你的代码,它对我来说很好
所以,尝试更换
$("[name='_ecp_custom_3']").attr("required", true);
用:
$('[name="_ecp_custom_3"]').attr('required', true);
所以,有时问题会出现双引号jquery