我试图通过编程方式添加自定义元框,但js给出了一个错误,目标是当我点击添加按钮时,同一个文本区框添加了哪个 是以前创建。我对在二17主题装箱定制metabox在function.php文件中的代码是:如何在post中添加自定义元字段与jQuery
// including custom js files here
function wptuts_scripts_with_jquery() {
wp_enqueue_script('custom-script', get_template_directory_uri() . '/js/myjs.js', array('jquery'));
}
add_action('admin_enqueue_scripts', 'wptuts_scripts_with_jquery');
// starting custom meta box
add_action('add_meta_boxes', 'm_param_meta_box_add');
function m_param_meta_box_add() {
add_meta_box('m_param_post', 'Box Title', 'm_param_post_meta_box_cb', 'post', 'normal', 'high');
}
function m_param_post_meta_box_cb($post)
{
$values = get_post_custom($post->ID);
if (isset($values['m_meta_description'])) {
$m_meta_description_text = esc_attr($values['m_meta_description'][0]);
}
wp_nonce_field('my_meta_box_nonce', 'meta_box_nonce');
?>
<div id="info"></div>
<label> Name: </label>
<textarea rows="1" cols="20" name="m_meta_description" ><?php echo $m_meta_description_text; ?></textarea>
<button type="button" name="add" id="add">Add</button><br><br>
<?php
} // close m_param_post_meta_box_cb function
add_action('save_post', 'cd_meta_box_save');
function cd_meta_box_save($post_id)
{
// Bail if we're doing an auto save
if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
// if our nonce isn't there, or we can't verify it, bail
if(!isset($_POST['meta_box_nonce']) || !wp_verify_nonce($_POST['meta_box_nonce'], 'my_meta_box_nonce')) return;
// if our current user can't edit this post, bail
if(!current_user_can('edit_post')) return;
// Make sure your data is set before trying to save it
if(isset($_POST['m_meta_description'])) {
update_post_meta($post_id, 'm_meta_description', wp_kses($_POST['m_meta_description']));
}
}
我的js代码的错误是:“遗漏的类型错误:$不在myjs.js功能 :2”
我的js代码是:在使用本
// <script type="text/javascript">
$(document).ready(
function(){
$("#add").click(function(){
$("#info").append('fname<input type="text" name="name[]">');
})
}
);
// </script>
护理的需要分享什么样的JS错误的你重新获得? –
编辑我的问题。 – Abhee