将值从表单字段复制到另一个字段时,如何用下划线替换空格 [英] How to replace whitespace with underscore when copy value from form field to another

查看:84
本文介绍了将值从表单字段复制到另一个字段时,如何用下划线替换空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人应该可以为我找到这个例子或举一个例子.

Someone should be able to find this example for me or give an example..

经过数小时的搜索,我仅在15个月大的时候使用Google中的一些bizare搜索词找到了答案,从而为我关闭了浏览器窗口,而没有用书标记它!我进行了私人浏览,因此没有保存我的历史记录:-(

After hours of searching I found the answer using some bizare search terms in Google only for my 15 month old to close the browser window for me without book marking it! I had private browsing on so it didn't save my history :-(

我有一个Web表单,我需要将一个表单字段的值传递给另一个表单字段,同时使用JQuery将下划线替换为下划线.

I have a web form, I need to pass the value of one form field to another form field at the same time replace the white space with underscore using JQuery.

我要寻找的例子

<input name="PageName" id="PageName" type="text" value="All About Us Page" />
<input name="PageURL" id="PageURL" type="hidden" value="all_about_us_page" />

因此,在提交表单时,它会为页面提供漂亮的格式化URL,而我对JavaScript或JQuery以及如何编写变量以使其正常工作并不了解.

so when the form is submitted it gives nice formatted URLs to the page(s) I don't know much about JavaScript or JQuery and how to write variable to make it work.

希望有人可以给出一个有效的例子,所以至少我可以使它起作用,进而帮助有人在寻找相同的解决方案,而这个标题在Google中应该排在很高的位置,以供其他人效仿.

Hope someone can give a working example, so at least I can get it working and in turn help someone searching in vien for the same solution the title of this should rank pretty high in Google for others to follow.

推荐答案

一个小jQuery插件可以执行以下操作(这会将 first 匹配元素的值放入匹配的元素集中通过传入的selector):

A little jQuery plugin to do something like this (this would put the value of the first matched element into the set of elements matched by the passed in selector):

$.fn.copyTo = function(selector) {
    $(selector).val($(this[0]).val().replace(/\s/g, "_"));
};

示例用法:

$("#source").copyTo("#dest");

这是一个工作示例.

这篇关于将值从表单字段复制到另一个字段时,如何用下划线替换空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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