使用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; }