个性化阅读
专注于IT技术分析

更改options-reading.php中的输入”min”属性

点击下载

我想从我的functions.php文件中将posts_per_page输入的’min’属性更改为’2’。

options-reading.php

<input name="posts_per_page" type="number" step="1" min="1" id="posts_per_page" value="<?php form_option( 'posts_per_page' ); ?>" class="small-text" /> <?php _e( 'posts' ); ?>

这是我所拥有的, 但不起作用。

functions.php

function my_enqueue($hook) {

    if ( 'options-reading.php' != $hook ) {
        return;
    }

    wp_enqueue_script( 'custom-javascript', get_template_directory_uri() 
    .'/assets/js/custom.js', '20151215', true );
}
add_action( 'admin_enqueue_scripts', 'my_enqueue');

custom.js

jQuery("#posts_per_page").attr({
   "min" : 2
});

附注:我在options-reading.php的末尾添加了javascript代码, 并且效果很好, 所以看起来问题与javascript不相关。


#1


你是否使用JS尝试过?

var input = document.getElementById("posts_per_page");
    input.setAttribute("min", 2);
赞(0)
未经允许不得转载:srcmini » 更改options-reading.php中的输入”min”属性

评论 抢沙发

评论前必须登录!