您的位置:首页 > Web前端 > JavaScript

JavaScript向php传递参数

2015-08-03 19:40 671 查看
在JavaScript中往往不能将参数进行写操作,这里可以将其发送给php页面,然后利用php对其进行存储

新建一个new.html,放入如下代码

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>solution_description</title>
</head>

<body>

<h2>Description</h2>

<div id="showText">
<textarea cols=120 rows=10 name="content" id="content" style="overflow: auto" readOnly="readOnly"  disabled="disabled"></textarea><br/>
</div>

<script type="text/javascript">
window.onload= loadText;
function loadText()
{
var abc = document.getElementById("content");
abc.value = "this is a test";
}

function modify()
{
var cObj = document.getElementById("content");
cObj.removeAttribute("readOnly");
cObj.removeAttribute("disabled");
}

function SaveDescription()
{
var cObj = document.getElementById("content");
cObj.setAttribute("readOnly",'true');
cObj.setAttribute("disabled",'disabled');
document.getElementById('txtcontent').value = cObj.value;
alert (document.getElementById('txtcontent').value);

}
</script>

<div id="buttons">
<form action="abc.php" method="post">
<input type="button" value="modify" onClick="modify()" />
<input type="submit" value="save" onClick="SaveDescription()" />
<input type="hidden" name="txtcontent" id="txtcontent" >
</form>
</div>

</body>
</html>

同一个目录下 建一个 abc.php文件,放入如下代码

<?php
echo $_POST["txtcontent"];
?>


<input type="hidden" name="txtcontent" id="txtcontent" >

这个的功能是传递一些参数,同时不需要再界面显示控件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: