使用Control + S保存Web表单内容

We've all used word processing applications like Microsoft Word and if there's one thing they've taught you it's that you need to save every few seconds in anticipation of the inevitable crash. WordPress has mimicked this functionality within their WYSIWYG editor and I use it frequently. Here's how to listen for "CONTROL+S" using MooTools.

我们都使用过像Microsoft Word这样的文字处理应用程序,如果它们教会了您一件事,那就是您需要每隔几秒钟就保存下来,以免发生不可避免的崩溃。 WordPress在其所见即所得(WYSIWYG)编辑器中模仿了此功能,我经常使用它。 这是使用MooTools收听“ CONTROL + S”的方法。

HTML (The HTML)


<form method="post" id="edit-form">
<textarea style="width:400px;height:250px;" name="content" id="content-box"><?php echo $_POST['content']; ?></textarea><br />
<input type="submit" id="save-button" value="Save and Continue" />
</form>


A simple form -- no modifications needed for this functionality to work.

简单的形式-无需修改即可使用此功能。

MooTools JavaScript (The MooTools JavaScript)


(function($) {
	window.addEvent('domready',function() {
		$('content-box').addEvent('keydown',function(event) {
			if((event.control || event.meta) && event.key == 's') {
				event.stop();
				$('edit-form').submit();
			}
		});
	});
})(document.id);


On the keydown event we listen for CONTROL+S (or META+S on Macs) and if the key is "s", we trigger form submission. I've not attempted to show you the AJAX method because that type of system would be very specific to your database/server-side language.

在keydown事件中,我们监听CONTROL + S(在Mac上为META + S),如果键为“ s”,则触发表单提交。 我没有尝试向您展示AJAX方法,因为这种类型的系统将非常特定于您的数据库/服务器端语言。

Crazy, sexy, cool, just like TLC from the 90's!

疯狂,性感,酷酷,就像90年代的TLC一样!

翻译自: https://davidwalsh.name/control-save

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值