按钮发布HTML

时间:2011-01-12 07:37:18

标签: javascript html postdata

我需要在不使用表单的情况下使用按钮。如何将帖子数据发送到浏览器?

我正在使用:

<button style="height: 100px; width: 300px" onClick="parent.location='form1.php'" >Fill survey</button>

1 个答案:

答案 0 :(得分:24)

您需要在JavaScript中创建表单,然后提交。看看这段代码

HTML

<button type="button" onclick="proceed();">do</button> 

JavaScript代码

function proceed () {
    var form = document.createElement('form');
    form.setAttribute('method', 'post');
    form.setAttribute('action', 'http://google.com');
    form.style.display = 'hidden';
    document.body.appendChild(form)
    form.submit();
}