关于如何使就地编辑可降解有什么想法吗?
我目前正在为 MooTools 编写一个就地编辑脚本,我有点困惑如何让它在不使用 JavaScript 的情况下优雅地降级,同时仍然具有一些功能。 我想以某种方式使用渐进增强。 我不是在寻找代码,而是在寻找如何处理这种情况的概念。 如果您有任何想法或知道任何可以优雅降级的就地编辑脚本,请分享。
I'm currently writing an edit-in-place script for MooTools and I'm a little stumped as to how I can make it degrade gracefully without JavaScript while still having some functionality. I would like to use progressive enhancement in some way. I'm not looking for code, but more a concept as to how one would approach the situation. If you have any ideas or know of any edit-in-place scripts that degrade gracefully, please share.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
听起来你可能是从错误的方向来处理这个问题的。 您实际上应该创建一个非 Javascript 版本进行编辑,然后在页面加载后使用 Javascript 添加就地编辑,而不是创建就地编辑并使其很好地降级(优雅降级角度),请参考作为渐进增强。
有两种选择。 将显示创建为带有无需 Javascript 即可工作的提交按钮的表单,然后使用 Javascript 将输入替换为某种执行就地编辑的标签。 您应该能够使用标签和 id 属性的组合来选择正确的属性,以使就地编辑实现正常工作。 如果您不希望默认显示表单,则另一个选项是使用按钮/链接显示值,以便使用服务器端处理将其转换为表单,然后添加就地编辑。
It sounds like you might be approaching this from the wrong direction. Rather than creating the edit-in-place and getting it degrade nicely (the Graceful Degradation angle), you should really be creating a non-Javascript version for editing and then adding the edit-in-place using Javascript after page load, reffered to as Progressive Enhancement.
There are two options for this. Create the display as a form with a submit button that works without Javascript, then using Javascript replace the inputs with some kind of label that performs the edit-in-place. You should be able to use a combination of labels and id attributes to pick out the correct properties for your edit-in-place implementation to work. The other option if you don't want a form to display by default is to display the values with an button/link for turning it into a form using server-side processing, then adding the edit-in-palce to that.
如果没有 JavaScript,您根本无法进行就地编辑,因此对其进行优雅降级包括确保用户在 JavaScript 不可用时仍然可以编辑相关项目。
因此,我只需一个链接来编辑相关的整个项目,然后在页面加载时在 JavaScript 中创建就地编辑控件,如果您不想让用户使用就地编辑,则隐藏编辑链接有空的时候。
You can't do edit-in-place at all without JavaScript, so graceful degradation for it consists of making sure that the user can still edit the item in question when JavaScript isn't available.
As such, I'd just have a link to edit the entire item in question and then create the edit-in-place controls in JavaScript on page load, hiding the edit link if you'd rather than users use edit-in-place when available.
如果是文本内容,您可以将可编辑内容显示为输入类型提交按钮,并将内容作为标题。 单击时,它将提交整个表单,保留其他值,并显示一个编辑对话框。 之后可以恢复表单值。
If it's textual content, you could show the editable content as an input type submit button, with as caption the content. When clicked, it would submit the entire form, preserving the other values, and show an edit dialog. Afterwards the form values could be restored.
也许将输入放在每个具有就地编辑功能的元素下的 div 中。 当页面加载时,使用 javascript 隐藏这些 div。 这样它们只有在 javascript 永远不会触发的情况下才可用。
Maybe put an input in a div under each element that has an edit-in-place. When the page loads, use javascript to hide those divs. That way they'll only be usable if the javascript never fires.
我假设您想要做的事情类似于以下场景:
其中 是一个替代 的按钮 带有 ,以便可以对其进行编辑。 有几种方法可以使其优雅地降级(即无需 javascript 即可工作)。
理论上:
使用 CSS,使用伪选择器来实现。 :active 有点像 onclick 事件,因此如果您嵌套隐藏的 在
这可能在您最喜欢的浏览器中有效,但您毫无疑问会发现它在 IE 中无法正常工作。
实践:
使用链接。 有那个 是一个实际链接,该链接转到已在服务器端完成此输入/跨度替换的页面。 您将事件处理程序粘贴在 上 有JS的人使用MooTools取消点击事件,像这样:
I'm asuming what you're trying to do is something like the following scenario:
Where the <a> is a button that replaces the <span> with an <input>, so that it can be edited. There are a couple of ways to make this degrade gracefully (ie work without javascript).
In theory:
Using CSS, do it with psuedo-selectors. :active is somewhat like an onclick event, so if you nest a hidden <input> in the <li>, this CSS hides the <span> and shows the <input> when the li is clicked on.
This may work in your favorite browser, but you'll without doubt find that it breaks in IE.
In practice:
Use a link. Have that <a> be an actual link that goes to a page where this input/span substitution has been done server side. You stick an event handler on the <a> that uses MooTools to cancel the click event for people who have JS, like this:
尝试使用样式化的输入文本,并在页面加载后使用 readonly 属性将其设为只读。
当单击它时,删除只读属性,并 onblur 使其再次只读。
单击“保存”按钮或 onblur 事件时,发出 Ajax 请求以将数据保存在服务器中。
Try using a styled input text, and after the page loaded make it readonly, using the readonly attribute.
and when click on it remove the readonly attribute, and onblur making it readonly again.
when clicking on "Save" button or on onblur event make an Ajax Request to save the data in the server.