在输入字段中找到左括号和右括号,将其删除(以及内部的所有内容)? [英] Finding opening and closing parentheses in an input field, delete them (together with everything inside)?

查看:182
本文介绍了在输入字段中找到左括号和右括号,将其删除(以及内部的所有内容)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用jQuery完成以下操作:在ID为#post_tag_names的输入字段中找到一个左括号和右括号,并将其从输入字段中删除(连同括号中的内容一起使用).

I would like to accomplish the following with jQuery: find an opening and closing parenteshes in the input field with the ID of #post_tag_names and remove them from he input field (together with the content inside the parentheses).

例如,如果输入字段具有以下内容:

For example, if the input field has this:

rails (30)

它应该像这样结束:

rails

如何做到这一点?

编辑

我已经有触发事件:

$('#post_tag_names').bind('railsAutocomplete.select', function(event, data){
  /* I NEED THIS PART */
});

推荐答案

您可以执行以下操作:

$input.val( $input.val().replace(/\(.+\)/, '') );

这篇关于在输入字段中找到左括号和右括号,将其删除(以及内部的所有内容)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆