【问题标题】:Change input 'min' attribute in options-reading.php更改 options-reading.php 中的输入“min”属性
【发布时间】:2018-11-05 19:43:11
【问题描述】:

我想从我的 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
});

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

【问题讨论】:

  • 试试jQuery("#posts_per_page").attr("min", 2);
  • 同理,不行。
  • 文件是custom.php还是custom.js
  • 抱歉,这是 custom.js,已经修复。

标签: javascript php jquery wordpress wordpress-theming


【解决方案1】:

您是否尝试过使用JS

var input = document.getElementById("posts_per_page");
    input.setAttribute("min", 2);

【讨论】:

  • 是的,我尝试并抛出了一个错误(未捕获的 TypeError:无法读取属性 'setAttribute' of null)
  • 在文件custom.js中
  • 尝试将代码放在options-reading.php脚本正文结束前
  • 别忘了把js放在script标签里
  • 我更新了我的问题,是的,在 options-reading.php 的末尾工作得很好,但我需要从我的 functions.php 文件中更改属性。
猜你喜欢
  • 1970-01-01
  • 2018-02-16
  • 2013-09-27
  • 1970-01-01
  • 2013-05-17
  • 2021-08-23
  • 2022-01-18
  • 1970-01-01
  • 2018-08-13
相关资源
最近更新 更多