文档就绪功能 - 添加提交按钮

时间:2017-03-01 15:36:42

标签: javascript php jquery html

这是代码 -

<script type="text/javascript">
    $(document).ready(function() {
        var data = new Array();
        data['result'] = '5';
        data['x_invoice'] = '123456';
        data['x_iduser'] = '23456';
        data['x_description'] = 'Desbloquear iPhone 6 Plus';
        data['x_document'] = '45767';
        data['x_amount'] = '24690.00';
                    data['x_amount_usd'] = '35.93';
                data['x_parent_invoice'] = '';
        data['x_control'] = 'dfhdfghfdgsdf';
        console.log(data);
        $.global.redirect_with_post('https://somedomain.com', data);
    });
</script>

这个代码在页面加载时自动重定向,所以我停止了JavaScript来更改参数,现在我被卡住了,因为我需要用提交按钮提交它

这可能吗?

这样试试没有运气

<input type="submit" onclick="function">

在javascript

之后添加此代码

3 个答案:

答案 0 :(得分:1)

快速评论 - 更短的语法而不是data = new Array()

var data = {
   result    : 5,
   x_invoice : '123456',
   x_iduser  : '23456'
   // etc...
}

答案 1 :(得分:0)

你应该:

<script type="text/javascript">
    function clickedInput(){
        var data = new Array();
        data['result'] = '5';
        data['x_invoice'] = '123456';
        data['x_iduser'] = '23456';
        data['x_description'] = 'Desbloquear iPhone 6 Plus';
        data['x_document'] = '45767';
        data['x_amount'] = '24690.00';
                    data['x_amount_usd'] = '35.93';
                data['x_parent_invoice'] = '';
        data['x_control'] = 'dfhdfghfdgsdf';
        console.log(data);
        $.global.redirect_with_post('https://somedomain.com', data);
    };
</script>

<input type="button" onclick="clickedInput()"> <!-- See changed type -->

答案 2 :(得分:0)

HTML

<form id="myForm">
  <button type="submit">submit</button>
</form> 

JS

<script type="text/javascript">
        function onSubmit() {
          var data = new Array();
            data['result'] = '5';
            data['x_invoice'] = '123456';
            data['x_iduser'] = '23456';
            data['x_description'] = 'Desbloquear iPhone 6 Plus';
            data['x_document'] = '45767';
            data['x_amount'] = '24690.00';
                        data['x_amount_usd'] = '35.93';
                    data['x_parent_invoice'] = '';
            data['x_control'] = 'dfhdfghfdgsdf';
            console.log(data);
            $.global.redirect_with_post('https://somedomain.com', data);
        }

        $(document).ready(function() {
          var form = document.getElementById("myForm");
          form.addEventListener("submit", onSubmit);
        });
</script>