我正在使用blur()将用户在表单中写入的内容复制到注册向导末尾的摘要页面。这很好。jquery触发加载模糊的所有输入元素
但是,当我预设一些字段值,这些都是正确的,没有被复制,因为用户可能不会与该特定字段进行交互。他们只会继续点击。
有没有办法触发所有的文本字段,textareas为了获得这些值复制以及?
这是我使用的功能:
/**
* 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'); });
我应该在哪里放触发()事件? 我使用触发器()在选择>第一个选项后,一旦使用getJSON获取列表,以便在链接选择事件中自动填充下一个列表。 但是,这是一个有点不同......
不是直接的方式,但你可以设置所有可能的事件,如键盘keydown等等来处理Your_copier函数。如果我没有得到您的问题点请告诉我 –