简体   繁体   English

如何添加新的文本框并下拉?

[英]How to add a new row of text box and drop down?

I'm currently working on a rails project. 我目前正在从事Rails项目。

I have a text_field and a select_tag on the same row. 我在同一行上有一个text_field和一个select_tag。 I want a new row of text box and drop down list to be created whenever I have at least one character typed in the current text box. 我希望每当在当前文本框中键入至少一个字符时,都将创建新的文本框和下拉列表行。 But I'm not sure how to do so. 但是我不确定该怎么做。 I assume I'd need to use jquery? 我假设我需要使用jQuery? But I'm still a newbie with web programming... 但是我还是Web编程的新手...

Please help! 请帮忙! Many thanks!!! 非常感谢!!!

You'd add fields and then apply a hidden value to them using jQuery's document ready function. 您将添加字段,然后使用jQuery的文档准备功能将隐藏值应用于它们。 Then apply a keyup function to the existing field you want it to trigger off of that calls show on the hidden item. 然后将一个keyup函数应用于您希望其触发隐藏项目上显示的调用的现有字段。

Here's the jquery I used in a wordpress page to do exactly that: 这是我在wordpress页面中使用的jQuery来做到的:

$(document).ready(function() {
  $("#fieldtohide").hide();
  $("#nonhiddenfield").keyup(function() {
    $("#fieldtohide").show();
  });
});

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

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