通过按特定键清除textarea的内容

时间:2016-01-18 07:30:38

标签: javascript textarea

每次用户按ENTER键我都需要清除textarea的内容。

$("#write").keyup(function(event) {
  if (event.keyCode == 13) {
    $(this).value = "";
    $(this).html = "";
    $(this).text = "";
  }
});
<textarea id="write"></textarea>

没有任何作用。

2 个答案:

答案 0 :(得分:2)

试试这个,使用val方法获取值

function userpage_rewrite_catch() {
global $wp_query;

if ( array_key_exists( 'ebooks_id', $wp_query->query_vars ) ) {
            include WP_PLUGIN_DIR .'/'. plugin_basename( dirname(__FILE__) ) .'/single-ebook.php';
exit;
}
}
add_action( 'template_redirect', 'userpage_rewrite_catch' );

function userpage_rewrite() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
add_action('init','userpage_rewrite');


function ebook_plugin_activate() {
  products_plugin_rules();
  flush_rewrite_rules();
 }

 function ebook_plugin_deactivate() {
  flush_rewrite_rules();
 }

 function ebook_plugin_rules() {
  //add_rewrite_rule('ebook/?([^/]*)', 'index.php?pagename=ebook&ebook_id=$matches[1]', 'top');
      add_rewrite_rule( 'ebooks/([^/]+)/([^/]*)/([^/]*)', 'index.php?ebooks=$matches[1]&ebook_cat=$matches[2]&ebooks_id=$matches[3]', 'top' );
 }

 function ebook_plugin_query_vars($vars) {
   $vars[] = 'ebooks';   
  $vars[] = 'ebook_cat';
  $vars[] = 'ebooks_id';
  return $vars;
 }

 //register activation function
 register_activation_hook(__FILE__, 'ebook_plugin_activate');
 //register deactivation function
 register_deactivation_hook(__FILE__, 'ebook_plugin_deactivate');
 //add rewrite rules in case another plugin flushes rules
 add_action('init', 'ebook_plugin_rules');
 //add plugin query vars (product_id) to wordpress
 add_filter('query_vars', 'ebook_plugin_query_vars');

答案 1 :(得分:0)

您已正确完成但缺少的部分仅为$(this)[0].value=""; 当您使用val()时,如果您使用value则选择对象,然后进入对象并使用$(this)[0]

的方法