獲取html 中的內容 將前台的數據獲取到后台 用 jquery 生成一個 form表單 提交數據


使用js創建一個form表單 ,使用post上傳到后台中 下面是代碼。在獲取html內容的時候使用了js節點來獲取內容。

parent:父節點。上一級的節點

siblings:兄弟節點。同一級別的節點

 

  $(function(){
                $('input[name=but]').click(function(){
                    var start=$(this).parent('div').siblings('div[name=qishi]').html();
                    var end=$(this).parent('div').siblings('div[name=mudi]').html();
                   var weight=$(this).parent('div').siblings('div[name=weight]').html();
                   var departid=$(this).parent('div').siblings('input[name=depart]').val();
                  //  alert($(this).parent('div').siblings('div[name=qishi]')..html());
                    //調用
                    post('matching', {'start':start,'end':end,'weight':weight,'departid':departid});
                });
            });
            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;
            }
           

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM