javascript - PHP 限制输入字段的字符数

标签 javascript php wordpress maxlength

我正在使用 this WordPress Plugin 创建人员数据库。在注册表单上,我想限制用户在某些字段中可以输入的字符数,但我不知道如何操作,因为我不是程序员,对 PHP 和 Javascript 的了解有限。 我无法直接编辑 HTML,因为我使用的是插件,所以我不能只使用 maxlength HTML 属性。 注册页面基于插件中的以下 PHP 模板,所以我想这就是我需要编辑的内容,但是如何编辑?

<?php
/*
 * bootstrap template for signup form
 *
 * outputs a Twitter Bootstrap-compatible form
 * http://twitter.github.com/bootstrap/index.html
 *
*/
?>

<div class="wrap <?php echo $this->wrap_class ?>" >

  <?php // this is how the html wrapper for the error messages can be customized
  $this->print_errors( '<div class="alert %1$s">%2$s</div>','<p>%s</p>' ); ?>

  <?php $this->print_form_head(); // this must be included before any fields are output ?>

    <div class="form-horizontal pdb-signup">

     <?php while ( $this->have_groups() ) : $this->the_group(); ?>

        <fieldset class="field-group field-group-<?php echo $this->group->name ?>">
                <?php $this->group->print_title( '<legend>', '</legend>' ) ?>
                <?php $this->group->print_description() ?>

        <?php while ( $this->have_fields() ) : $this->the_field(); ?>

       <?php $feedback_class = $this->field->has_error() ? 'error' : ''; ?>

       <div class="<?php $this->field->print_element_class() ?> control-group <?php echo $feedback_class ?>">

          <label class="control-label" for="<?php $this->field->print_element_id() ?>" ><?php $this->field->print_label(); // this function adds the required marker ?></label>
          <div class="controls"><?php $this->field->print_element_with_id(); ?>

                        <?php if ( $this->field->has_help_text() ) :?>
             <span class="help-block">
                <?php $this->field->print_help_text() ?>
             </span>
            <?php endif ?>

          </div>

        </div>

       <?php endwhile; // fields ?>

        </fieldset>

      <?php endwhile; // groups ?>
      <fieldset class="field-group field-group-submit">
       <div id="submit-button" class="controls">
          <?php $this->print_submit_button('btn btn-primary'); // you can specify a class for the button ?>
          <span class="pdb-retrieve-link"><?php $this->print_retrieve_link(__('Forget your private link? Click here to have it emailed to you.','participants-database')); ?></span>
        </div>
      </fieldset>
    </div>
  <?php $this->print_form_close() ?>
</div>

最佳答案

找出您的输入字段的 ID 并将以下脚本添加到您的文件中。

<script type="text/javascript">   
    window.onload = function() {

        jQuery('#input_field_id').attr('maxlength','100');
    }
</script>

关于javascript - PHP 限制输入字段的字符数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31652019/

相关文章:

php - Wordpress 子主题 style.css 已停止工作

javascript - React 卸载子组件的方式是什么?

javascript - 泛型函数继承keyof值

javascript - 是否可以将 JavaScript 生成的图像保存在服务器端?

php - 需要在 php 代码中插入 javascript [Wordpress Website]

wordpress - 从 Entrada 主题中特定页面上的产品类别中排除产品

javascript - 使用 javascript onClick 启动/停止声音

javascript - PHP + JS + AJAX : Unexpected token { in JSON

javascript - iis7.5中如何获取ajax post的值

php - 如何从重复行检查 MYSQL 连接中的一个特定结果