JQuery:尝试验证自定义 WordPress 字段内的输入字段
JQuery: Trying to validate input field inside of Custom WordPress field
在尝试验证我在 The Events Calendar for WordPress 中创建的自定义字段时遇到问题,我的活动页面中有许多自定义字段/post。它使用标准 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 一个很好用,但自定义一个返回错误消息:
Parsing Error: Unexpected token _ecp_custom_3
那么我怎样才能让这个字段使用名称元素而不是 ID 来验证呢?
我试过你的代码,对我来说效果很好
所以,尝试替换
$("[name='_ecp_custom_3']").attr("required", true);
与 :
$('[name="_ecp_custom_3"]').attr('required', true);
所以,有时候双引号会出现问题jquery
在尝试验证我在 The Events Calendar for WordPress 中创建的自定义字段时遇到问题,我的活动页面中有许多自定义字段/post。它使用标准 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 一个很好用,但自定义一个返回错误消息:
Parsing Error: Unexpected token _ecp_custom_3
那么我怎样才能让这个字段使用名称元素而不是 ID 来验证呢?
我试过你的代码,对我来说效果很好
所以,尝试替换
$("[name='_ecp_custom_3']").attr("required", true);
与 :
$('[name="_ecp_custom_3"]').attr('required', true);
所以,有时候双引号会出现问题jquery