php/js -> implement a simple notepad

 

 

 

<!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>Tasks</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 to save
document.onkeydown=function()   {
    if (event.ctrlKey == true && event.keyCode == 83) {//Ctrl+S
		document.getElementById("btn_save").click();
        event.returnvalue = false;
		return false;         
    }
 
}

// put the cursor on the last character
var sr=document.getElementById("content");
var len=sr.value.length;
setSelectionRange(sr,len,len); //position the cursor to the end of the text

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>

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327062402&siteId=291194637