【发布时间】:2012-06-08 09:55:36
【问题描述】:
我正在使用 blur() 将用户在表单中写入的内容复制到注册向导结束时的摘要页面中。这很好用。
但是当我预设一些字段值并且这些值是正确的时,不会复制任何内容,因为用户可能不会与该特定字段进行交互。他们只会点击继续。
有没有办法触发所有文本字段、文本区域,以便同时复制这些值?
这是我正在使用的功能:
/**
* Author: Thomas Kile
* Desc: Copy text from a form element into a given tag.
**
* @param string $type type of form element
* @param string $from Id of form element to copy text/value from.
* @param string $to Id of element to copy text/value into.
*/
function copyFormData(type,from,to)
{
switch (type)
{
case 'text': var copied_text = $(from).val(); break; // get input text value
case 'select': var copied_text = $(from+' option:selected').text(); break;
}
$(to).text(copied_text); // put inside this tag
}
这就是我的使用方式:
$(firstName).blur(function(){ copyFormData('text',firstName,'strong#firstName'); });
$(lastName).blur(function(){ copyFormData('text',lastName,'strong#lastName'); });
我应该在哪里放置 trigger() 事件? 在使用 getJSON 获取列表后,我在 select>first 选项上使用了 trigger(),以便在链式选择事物中自动填充下一个列表。 但这有点不同......
【问题讨论】:
-
不是直接方式,但您可以设置所有可能的事件,如键盘按键等,以使用 Your_copier 函数处理。如果我没有明白你的问题,请告诉我
标签: jquery events triggers copy