jquery在加载时触发所有输入元素

Tho*_*asK 1 jquery events triggers copy

我正在使用blur()将用户在表单中写入的内容复制到注册向导末尾的摘要页面中.这很有效.

但是当我预设一些字段值并且这些是正确的时,没有任何内容被复制,因为用户可能不会与该特定字段进行交互.他们只会点击继续.

有没有办法触发所有文本字段,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
    }
Run Code Online (Sandbox Code Playgroud)

这就是我使用它的方式:

$(firstName).blur(function(){   copyFormData('text',firstName,'strong#firstName');  });
$(lastName).blur(function(){    copyFormData('text',lastName,'strong#lastName');    });
Run Code Online (Sandbox Code Playgroud)

我应该在哪里放置一个trigger()事件?一旦使用getJSON获取列表,我就在select> first选项上使用了trigger(),以便在链式选择事件中自动填充下一个列表.但那有点不同......

Ser*_*nko 10

你可以使用技巧:)

$('input').each(function(){
  $(this).trigger('blur');
  //each input event one by one... will be blured
})
Run Code Online (Sandbox Code Playgroud)