【问题标题】:Auto type from input to textarea and wrap text in textarea?自动从输入到textarea并在textarea中换行?
【发布时间】:2017-09-12 13:43:50
【问题描述】:

当我在此输入字段中输入时:

<fieldset class="usp-title">
  <label for="user-submitted-title"><?php esc_html_e('Search', 'usp'); ?></label>
  <input id="user-submitted-title" 
         name="user-submitted-title" 
         type="text" 
         value="" 
         placeholder="<?php esc_attr_e('Search', 'usp'); ?>"<?php if (usp_check_required('usp_title')) echo $usp_required; ?> class="usp-input">
</fieldset>

我希望它自动输入这个字段,但是这里的文本应该被标签包围:

<fieldset class="usp-content">
  <?php if ($usp_options['usp_richtext_editor'] == true) { ?>

  <div class="usp_text-editor">
    <?php $usp_rte_settings = array(
      'wpautop' => true,  // enable rich text editor
      'media_buttons' => true,  // enable add media button
      'textarea_name' => 'user-submitted-content', // name
      'textarea_rows' => '10',  // number of textarea rows
      'tabindex' => '',    // tabindex
      'editor_css' => '',    // extra CSS
      'editor_class' => 'usp-rich-textarea', // class
      'teeny' => false, // output minimal editor config
      'dfw' => false, // replace fullscreen with DFW
      'tinymce' => true,  // enable TinyMCE
      'quicktags' => true,  // enable quicktags
      'drag_drop_upload' => true,  // enable drag-drop
    );
    $usp_rte_settings = apply_filters('usp_editor_settings', $usp_rte_settings);
    $usp_editor_content = apply_filters('usp_editor_content', '');
    wp_editor($usp_editor_content, 'uspcontent', $usp_rte_settings); ?>
  </div>
  <?php } else { ?>

    <label for="user-submitted-content"><?php esc_html_e('Post Content', 'usp'); ?></label>
    <textarea id="user-submitted-content" name="user-submitted-content" rows="5" placeholder="<?php esc_attr_e('Post Content', 'usp'); ?>"<?php if (usp_check_required('usp_content')) echo $usp_required; ?> class="usp-textarea"></textarea>
        <?php } ?>

</fieldset>

第二个字段应该是由[bbcode]copied from input[bbcode]包围的文本

【问题讨论】:

  • 使用 .keydown 事件,完成后只需将值从一个文本框上传到另一个文本框,同时在变量周围附加标签
  • 我试过了,但我没有成功,请你帮我写代码。我不擅长编码。

标签: javascript php jquery input textarea


【解决方案1】:

只需将 keyup 事件添加到'from'文本框并设置'to'文本框/区域的值

$('#user-submitted-title').on('keyup',function(e){
  $('#user-submitted-content').val('[bbcode]'+ $(this).val() +'[bbcode]');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type='text' id='user-submitted-title'/>
<textarea id='user-submitted-content'></textarea>

【讨论】:

    【解决方案2】:
    // When the user types a letter
    
    $("#user-submitted-title").keyup(function(){
      // Grab the value, append the tags and drop it into the textarea
      $("#user-submitted-content").val("[bbcode]"+$(this).val()+"[bbcode]"); 
    });
    

    【讨论】:

      猜你喜欢
      • 2015-09-13
      • 1970-01-01
      • 1970-01-01
      • 2017-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 1970-01-01
      相关资源
      最近更新 更多