简体   繁体   English

jQuery:如何在更改输入元素后仅使输入新行一次

[英]jQuery: How to make a new row of inputs only once after the change of an input element

I kind of stumbled into an obstacle here. 我有点在这里遇到障碍。 For a form I have the following inputs: 对于表单,我有以下输入:

 <table> <tr> <td>Lening 1</td> <td> <input type="text" name="lening-Maatschappij" size="40" placeholder="Maatschappij"> </td> <td> <input type="text" name="lening-Restantschuld" size="40" placeholder="Restantschuld"> </td> </tr> <tr> <td> <input type="text" name="lening-Maandbedrag" size="40" placeholder="Maandbedrag"> </td> <td> <input type="text" name="lening-Jaarrente" size="40" placeholder="Jaarrente"> </td> <td> <select name="lening-inlossen" id="lening-inlossen"> <option disabled="">Inlossen</option> <option value="Ja">Ja</option> <option value="Nee">Nee</option> </select> </td> </tr> </table> 

What I want to do is make sure that if one of these input fields loses focus (I assume focusOut will work here), but contains text, these rows are created again, but with Lening 2 as the first label. 我想做的是确保如果这些输入字段之一失去焦点(我认为focusOut将在此处工作),但包含文本,则会再次创建这些行,但将Lening 2作为第一个标签。 So it should end up like this: 所以它应该像这样结束:

 <table> <tr> <td>Lening 1</td> <td> <input type="text" name="lening-Maatschappij" size="40" placeholder="Maatschappij"> </td> <td> <input type="text" name="lening-Restantschuld" size="40" placeholder="Restantschuld"> </td> </tr> <tr> <td> <input type="text" name="lening-Maandbedrag" size="40" placeholder="Maandbedrag"> </td> <td> <input type="text" name="lening-Jaarrente" size="40" placeholder="Jaarrente"> </td> <td> <select name="lening-inlossen" id="lening-inlossen"> <option disabled="">Inlossen</option> <option value="Ja">Ja</option> <option value="Nee">Nee</option> </select> </td> </tr> <tr> <td>Lening 2</td> <td> <input type="text" name="lening-Maatschappij" size="40" placeholder="Maatschappij"> </td> <td> <input type="text" name="lening-Restantschuld" size="40" placeholder="Restantschuld"> </td> </tr> <tr> <td> <input type="text" name="lening-Maandbedrag" size="40" placeholder="Maandbedrag"> </td> <td> <input type="text" name="lening-Jaarrente" size="40" placeholder="Jaarrente"> </td> <td> <select name="lening-inlossen" id="lening-inlossen"> <option disabled="">Inlossen</option> <option value="Ja">Ja</option> <option value="Nee">Nee</option> </select> </td> </tr> </table> 

I just need to make sure that if I focus on the rows from Lening 1 I don't end up having a third row made, cause my focusOut event will be called again. 我只需要确保如果我将注意力集中在Lening 1的行上,就不会产生第三行,因为我的focusOut事件将再次被调用。

The question is: How can I make sure Lening 2 is only generated once when I type in the input fields of Lening 1 , and how can I make sure that Lening 3 is generated once when I type in the input fields of Lening 2 and so on? 现在的问题是:我怎样才能确保Lening 2 ,当我在输入字段中键入只产生一次 Lening 1 ,我怎么能确保Lening 3 ,当我在输入字段中键入生成一次 Lening 2等上?

I hope I formatted my question correctly. 我希望我正确格式化了我的问题。 It's had to summarize this into one sentence. 必须将其概括为一个句子。 I'm really not only asking this question, but also asking how to ask (Even after reading the how-to on asking I'm not sure if I'm doing this right) 我不仅在问这个问题,而且还在问如何提问(即使在阅读了“如何做”之后,我也不确定自己是否做得对)

Focusout() will be called repetitively. Focusout()将被重复调用。

You can do one thing when user starts typing into first row's first text box, the you can generate the row 2nd, when user starts typing into second rows first text box, row 3rd will appear and so on. 当用户开始在第一行的第一个文本框中输入内容时,您可以做一件事,您可以生成第二行;当用户开始在第二行的第一个文本框中输入内容时,将出现第三行,依此类推。

You need onkeyup event for that. 为此,您需要onkeyup事件。

$("#lening-Maatschappij_1").keyup(function(){
    // generated the row Lening 2
});
$("#lening-Maatschappij_2").keyup(function(){
    // generated the row Lening 3
});

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

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