简体   繁体   English

在表格中创建可编辑的新行

[英]Create editable new rows to a table

I'm trying to add details to a database by using ajax and table dynamic rows. 我正在尝试通过使用Ajax和表动态行将详细信息添加到数据库。

eg 例如

---- ----

{Customer: dropdown menu} | {客户:下拉菜单} | {Description: textarea} | {说明:textarea} | delete 删除

Add New Customer 添加新客户

--- ---

When the user clicks it shows the drop down menu of all available customers. 当用户单击时,将显示所有可用客户的下拉菜单。 when you click away it just shows the select customer name (not the dropdown menu) 当您单击离开时,它仅显示选择的客户名称(而不是下拉菜单)

Similarly with the description i want on click to allow them to edit the description of the text area but when you click away it only shows the text you just entered. 与描述类似,我希望单击以允许他们编辑文本区域的描述,但是单击时仅显示您刚刚输入的文本。 (not the text area outline) (不是文本区域轮廓)

Add new customer button creates a new empty row. 添加新客户按钮创建一个新的空行。

What libraries or examples can help me get started with this? 哪些库或示例可以帮助我入门?

I saw this recently in an application recently. 我最近在一个应用程序中看到了这一点。 In this application it was possible to add new items/rows via ajax and dynamic HTML. 在此应用程序中,可以通过ajax和动态HTML添加新项目/行。

You should be able to do that easily enough using jQuery (look at the selectors, events & manipulation in their docs). 您应该能够使用jQuery轻松地做到这一点(请查看其文档中的选择器,事件和操作)。 For example, for the dropdown 例如,对于下拉菜单

<span id="customer-name"></span>
<select name="customer-list" id="customer-list">
    <option class="name" value="cust-1">Frank Frankson</option>
    <option class="name" value="cust-2">John Johnson</option>
</select>

And the jQuery : 还有jQuery:

$('.name').click(function(){        
    $('#customer-name').text($(this).text());
    $('#customer-list').hide();
});

In that function you could do something with the option element value if needed (an ajax post or whatever). 在该函数中,您可以根据需要使用option元素值进行操作(ajax发布或其他操作)。

The principal for changing the Text Area description would be the same (you could grab the text out of the textarea, add it to a div & hide the textarea; if they need to edit again, just show the textarea & hide the div) 更改文本区域描述的原理是相同的(您可以从文本区域中抓取文本,将其添加到div中并隐藏文本区域;如果需要再次编辑,只需显示文本区域并隐藏div)

Use jQuery. 使用jQuery。

Use the tokenizing autocomplete plugin for jQuery 对jQuery使用标记化自动完成插件

For the inplace edit use Jeditable . 对于就地编辑,请使用Jeditable

I'd stay away from drop downs, they are almost always bad design, whether in a menu or selecting from a long list of options. 我会远离下拉菜单,无论是在菜单中还是从一长串的选项中进行选择,它们几乎总是糟糕的设计。 For something like a list of customers which is hopefully likely to be long it is an awful choice of a UI component. 对于希望可能很长的客户列表之类的东西,这是UI组件的糟糕选择。

The only time that it really makes sense to use a drop down is when the list of options is short and well known. 只有在选项列表简短众所周知的情况下,使用下拉菜单才真正有意义。 So for it to be acceptable it probably has to be a list of options which rarely if ever changes, is less than 10 or so items long, and is used frequently (so it is well known). 因此,要使其可接受,它可能必须是一个选项列表,该选项列表很少更改(少于10个左右),并且经常使用(众所周知)。 Drop downs are painful. 下降很痛苦。

Most sites where you see such functionality accomplish it with styling - you can style a text input box to look like plain text (by removing the border and setting the background color to transparent). 在大多数看到这种功能的网站上,它们都是通过样式实现的-您可以将文本输入框的样式设置为纯文本(通过删除边框并将背景色设置为透明)。 When the input is clicked on (focused), the style changes: 单击输入(突出显示)后,样式将更改:

<style>
   .blurredText { border: none; background-color: transparent; }
</style>
. . .
<input type="text" class="blurredText" value="Click me to edit"
    onfocus="this.className=''" 
    onblur="this.className='blurredText'"/>

Styling a select the same way may prove difficult however, since select controls are notoriously resistant to CSS. 但是,以相同的方式对选择进行样式设置可能会很困难,因为众所周知,选择控件耐CSS。 You can still use the method Dave proposed. 您仍然可以使用Dave建议的方法。

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

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