简体   繁体   English

关于如何使就地编辑可降解的任何想法?

[英]Any ideas on how to make edit-in-place degradable?

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. 我目前正在为MooTools写一个就地编辑脚本,对于在没有JavaScript的情况下如何使它正常降级的同时,我仍然有些困惑。 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. 如果您有任何想法或知道任何会优雅降级的就地编辑脚本,请分享。

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 . 与其创建一个就地编辑并使其降级到很好的程度(优美的降级角度),不如说是创建一个非Javascript版本进行编辑,然后在页面加载后使用Javascript添加就地编辑,以作为逐步增强

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. 使用无需Javascript即可使用的Submit按钮将显示形式创建为表单,然后使用Javascript将输入替换为执行现场编辑的某种标签。 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. 您应该能够使用标签和id属性的组合来选择正确的属性,以便就地编辑实现正常工作。 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. 如果您不希望默认显示表单,则另一种选择是显示带有按钮/链接的值,以便使用服务器端处理将其转换为表单,然后在其中添加编辑区域。

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. 如果没有JavaScript,就无法进行就地编辑,因此,要进行适当的降级包括确保在JavaScript不可用时,用户仍然可以编辑有问题的项目。

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. 这样,我只有一个链接,可以编辑整个问题,然后在页面加载时在JavaScript中创建就地编辑控件,如果您愿意而不是用户使用就地编辑,则可以隐藏编辑链接有空的时候。

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. 之后,可以恢复表单值。

Maybe put an input in a div under each element that has an edit-in-place. 也许在每个具有就地编辑的元素的下面的div中放置一个输入。 When the page loads, use javascript to hide those divs. 页面加载时,使用javascript隐藏这些div。 That way they'll only be usable if the javascript never fires. 这样,只有在javascript永不触发时,它们才可用。

I'm asuming what you're trying to do is something like the following scenario: 我假设您要执行的操作类似于以下情况:

<li>
    <span id="editable">Editable text</span> <a class="edit_button"> </a>
</li>

Where the <a> is a button that replaces the <span> with an <input>, so that it can be edited. <a>是将<span>替换为<input>的按钮,以便可以对其进行编辑。 There are a couple of ways to make this degrade gracefully (ie work without javascript). 有两种方法可以使它正常降级(即无需javascript就可以工作)。

In theory: 理论上:

Using CSS, do it with psuedo-selectors. 使用CSS,并使用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. :active有点像onclick事件,因此,如果在<li>中嵌套一个隐藏的<input>,则单击li时,此CSS将隐藏<span>并显示<input>。

li:active #editable {
    display:none;
}
li:active input{
    display:block;
}

This may work in your favorite browser, but you'll without doubt find that it breaks in IE. 这可能会在您最喜欢的浏览器中工作,但是毫无疑问,您会发现它在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. 将该<a>设置为实际链接,该链接将链接到已在服务器端完成此输入/跨度替换的页面。 You stick an event handler on the <a> that uses MooTools to cancel the click event for people who have JS, like this: 您将事件处理程序粘贴在<a>上,该处理程序使用MooTools取消具有JS的用户的click事件,如下所示:

function make_editable(evt) {
    var evt = new Event(evt);
    evt.preventDefault();
}

Try using a styled input text, and after the page loaded make it readonly, using the readonly attribute. 尝试使用样式化的输入文本,并在页面加载后使用readonly属性将其设置为只读。 and when click on it remove the readonly attribute, and onblur making it readonly again. 然后单击它,删除readonly属性,然后onblur将其重新设置为只读。 when clicking on "Save" button or on onblur event make an Ajax Request to save the data in the server. 当单击“保存”按钮或onblur事件时,发出Ajax请求以将数据保存在服务器中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM