jquery create form form

// catch the click event of the link
$('#btn').click(function(){
    // Get the parameters to submit
    var my_val = $.trim($('#ipt').val());
    // Get the URL of the page to submit
    var action = $(this).attr('href');
    // create Form
    var form = $('<form></form>');
    // set properties
    form.attr('action', action);
    form.attr('method', 'post');
    // The target attribute of the form determines which page the form is submitted on
    // _self -> current page _blank -> new page
    form.attr('target', '_self');
    // create Input
    var my_input = $('<input type="text" name="my_name" />');
    my_input.attr('value', my_val);
    // Append to Form
    form.append(my_input);
    // submit Form
    form.appendTo(document.body).submit();
    // Note the default action of return false to cancel the link
    return false;
});

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326759669&siteId=291194637