如何把JS获取的数据传递给php

<script type="text/javascript"> var oBtn = null; var oForm = null; var oText = null; var oTextarea = null; var timer = null; var speed = 0; var oLi = null var oH3 = null; var oP = null; window.onload = function() { oBtn = document.getElementById("btn"); oBtn.onclick = getValue; }; function getValue() { document.getElementById("message_text").style.display = "block"; oForm = document.getElementsByTagName("form")[0]; oText = document.getElementById("text"); oTextarea = document.getElementsByTagName("textarea")[0]; oUl = document.getElementById("message_text").getElementsByTagName("ul")[0]; oForm.onsubmit = function(){ return false; }; if( oText.value == "" || oTextarea.value == "" ) { alert("就二个框,你还不写全了啊?"); return; } oLi = document.createElement("li"); oH3 = document.createElement("h3"); oP = document.createElement("p"); oH3.innerHTML = oText.value; oP.innerHTML = oTextarea.value; if(oUl.childNodes[0]) { oUl.insertBefore(oLi,oUl.childNodes[0]); } else { oUl.appendChild(oLi); } oLi.appendChild(oH3); oLi.appendChild(oP); oText.value = ""; oTextarea.value = ""; var h = oLi.offsetHeight; oLi.style.height = '0px'; if(timer) { clearInterval(timer); } timer = setInterval("goTime("+h+")", 35); goTime(h); } function goTime(target) { var top = oLi.offsetHeight; speed += 3; top += speed; if(top > target) { top = target; speed *= -0.7; } if(top===target && Math.abs(speed) < 3) { clearInterval(timer); timer = null; oLi.style.height = target + "px"; } oLi.style.height = top + "px"; } </script> </head> <body> <div id="explain"> 不妨多提交几次留言试试看……</div> <div id="box"> <ul id="fill_in"> <form action="xxx.php" method="post"> <li>姓名:<input id="text" name="name" type="text" class="text" /></li> <li>内容:<textarea id="content" style="width:300px; height:100px"></textarea></li> <li><input id="btn" type="submit" value="提交" class="btn" /></li> </form> </ul> <div id="message_text"> <h2>显示留言</h2> <ul></ul> </div> </div> </body> 如何把这段JS获取的两个文本框的值传递给php

方法1 js的location 或 document 的url传值
方法2 js的submit提交
方法3 js的ajax

数据可以是简单的字符串 也可以是 json格式或 xml等
温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-09-28

    用ajax发送

    用javascript将数据填到form中,通过按钮提交

第2个回答  2012-02-11
要使用AJAX的....
相似回答