如何从文本框中删除特定文本,同时保持剩余文本完整

发布于 2025-01-08 03:43:23 字数 315 浏览 4 评论 0 原文

我试图替换模糊文本中的文本,因此如果用户输入:

Hello/test

我希望将其替换为:

test

我使用基本文本框:

<asp:TextBox runat="server" ID="fullName" CssClass="textBoxes"></asp:TextBox>

使用 asp.net 4.0 和 jquery。

我怎样才能做到这一点?

谢谢。

im trying to replace text in a text on blur so if the user enters this:

Hello/test

i want it to be replaced by:

test

im using a basic textbox:

<asp:TextBox runat="server" ID="fullName" CssClass="textBoxes"></asp:TextBox>

with asp.net 4.0 and jquery.

how can i do that?

thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

临风闻羌笛 2025-01-15 03:43:23

假设您希望它的功能仅保留 / 之后的字符串值,而不仅仅是简单地替换“Hello/”,请尝试以下操作:

$(".textBoxes").blur(function() {
    var values = $(this).val().split('/');
    $(this).val(values[values.length-1])
});

小提琴示例

Assuming the functionality you want it to only keep the value of the string after the /, not just to simply replace the 'Hello/', try this:

$(".textBoxes").blur(function() {
    var values = $(this).val().split('/');
    $(this).val(values[values.length-1])
});

Example fiddle

丢了幸福的猪 2025-01-15 03:43:23

您可以使用 RegExp 将不需要的字符串替换为空字符串:

$('textarea, input[type="text"]').on('blur', function () {
    this.value = this.value.replace(/(hello\/)/gi, '');
});

此正则表达式查找 hello/ 的任何实例(不区分大小写)并将其替换为空字符串。

这是一个演示: http://jsfiddle.net/K8xMf/

You can use RegExp to replace the unwanted string(s) with a blank string:

$('textarea, input[type="text"]').on('blur', function () {
    this.value = this.value.replace(/(hello\/)/gi, '');
});

This regular expression looks for any instance of hello/ (case-insensitive) and replaces it with a empty string.

Here is a demo: http://jsfiddle.net/K8xMf/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文