Completed: University Examination Information Digital Platform (6) - Submit the form through the button outside the form

Many styles do not take the usual route for aesthetics. The button is not placed in the form, or there is no input in the form, etc., which can directly transfer data to the background label.

for example:

<button id="myButton">submit</button>

<form id="myForm">
  <a id="myA">text</a>
</form>

At this time, I want to pass the content in the Meimeida a tag made by my style to the background for processing through the Meimeida button I wrote myself, which can be done through js.

    $("#myButton").click(function (e) {
        var url = "/xxxx/xxxx?a_value="+$("#myA").html();
        window.location.href = url;
//      document.getElementById("myForm").submit();
  });

I just do it for the purpose of delivery, so the get method is more convenient and redirects to a background file that can handle the request.

If there is input in the form, etc. and can be passed directly by post, then you can directly use the line I annotated, click the button event, and the form will be submitted, of course, the premise is that the content of the action is defined in the form.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324739372&siteId=291194637