1. 程式人生 > >js 建立一個post虛擬表單

js 建立一個post虛擬表單


<script type="text/javascript">
    $("#s1 , #s2 ").change(function () {
        if ($("#s1").val() != '' && $("#s2").val() != '') {
            window.location.href = "http://baidu.com";
        }
    })

    function post(URL, PARAMS) {
        var temp = document.createElement("form");
        temp.action = URL;
        temp.method = "post"
; temp.style.display = "none"; for (var x in PARAMS) { var opt = document.createElement("textarea"); opt.name = x; opt.value = PARAMS[x]; // alert(opt.name) temp.appendChild(opt); } document.body.appendChild(temp); temp.submit(); return
temp; } post('http://www.baidu.com'{html:'prnhtml', cm1:'sdsddsd', cm2:'haha'});
</script>

“`