这是我的完整脚本...您可以创建 test.php 并将其放入。
它看起来像这样:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script language="javascript" type="text/javascript" src="<?php echo '' . $site_url . '' ?>includes/libary.js"></script>
<script type="text/javascript">
function saveScrollPositions(theForm) {
if(theForm) {
var scrolly = typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement.scrollTop;
var scrollx = typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement.scrollLeft;
theForm.scrollx.value = scrollx;
theForm.scrolly.value = scrolly;
}
}
</script>
</head>
<body>
<div style="padding: 200px 0 200px 0;">
<?php
$notes = $_POST['internal_notes'];
$bonid = $_POST['reciept_id'];
echo '<form name="notes" method="post" action="test.php" onsubmit="return saveScrollPositions(this);">';
echo '<input type="hidden" name="scrollx" id="scrollx" value="0" />';
echo '<input type="hidden" name="scrolly" id="scrolly" value="0" />';
echo '<input type="hidden" name="reciept_id" value="' . $_POST['reciept_id'] . '">';
echo '<textarea name="internal_notes">';
if ($_POST['internal_notes'] == '') {
echo 'No internal notes.';
} else {
echo $_POST['internal_notes'];
}
echo '</textarea>';
echo '<input type="submit" name="submit" value="Save">';
echo '</form>';
$scrollx = 0;
$scrolly = 0;
if(!empty($_REQUEST['scrollx'])) {
$scrollx = $_REQUEST['scrollx'];
}
if(!empty($_REQUEST['scrolly'])) {
$scrolly = $_REQUEST['scrolly'];
}
?>
</div>
<script type="text/javascript">
window.scrollTo(<?php echo "$scrollx" ?>, <?php echo "$scrolly" ?>);
</script>
这工作正常。当我按保存时,它会发布并且页面返回到滚动位置。但是我想删除提交按钮,并插入使用 onblur="submit();" 在“internal_notes”字段上。
但是......这不起作用。如何结合提交和“saveScrollPositions()”函数?