php / js - > 实现一个简单的记事本

<!doctype html>
<html lang="en">
 <head>
	<meta charset="UTF-8">
	<meta name="Generator" content="EditPlus®">
	<meta name="Author" content="">
	<meta name="Keywords" content="">
	<meta name="Description" content="">
	<title>任务</title>
	<link type="text/css" rel="stylesheet" href=""/>
	<script src="" type="text/javascript"></script>

 </head>
 <body>
<?PHP

if(isset($_POST['update']) &&  $_POST['update']){
	$myfile = fopen("data.txt", "w") or die("Unable to open file!");
	$txt = $_POST['con'];

	fwrite($myfile, $txt);
	fclose($myfile);

	header("Location:./index.php?".rand(0,999));

}
?>

<style type="text/css">
	.box{width:500px;margin:0px auto}
</style>


<div class="box">
 <form method=post action="" name="" >
	<textarea style="font-size:14px;margin-top:10px;width:100%;height:400px;" name="con"  id="content"  ><?PHP echo file_get_contents("./data.txt");  ?></textarea><BR>	
	<input type="submit" id="btn_save"  style="width:300px;height:50px;background:blue;color:#fff" name="update" value="Update"><BR>
 </form>
</div>

<script language="javascript">
<!--

//ctrl + s 保存
document.onkeydown=function()   {
    if (event.ctrlKey == true && event.keyCode == 83) {//Ctrl+S
		document.getElementById("btn_save").click();
        event.returnvalue = false;
		return false;         
    }
 
}

// 将光标放到最后一个字符
var sr=document.getElementById("content");
var len=sr.value.length;
setSelectionRange(sr,len,len); //将光标定位到文本最后 

function setSelectionRange(input, selectionStart, selectionEnd) {
 if (input.setSelectionRange) {  
   input.focus();  
   input.setSelectionRange(selectionStart, selectionEnd);  
 }  
 else if (input.createTextRange) {  
   var range = input.createTextRange();  
   range.collapse(true);  
   range.moveEnd('character', selectionEnd);  
   range.moveStart('character', selectionStart);  
   range.select();  
 }  
} 
//\\===========

//-->
</script>

 

 </body>
</html>

猜你喜欢

转载自mft.iteye.com/blog/2387907