-1

我有一个文本区域

<textarea id="realAreaWhereUserTypes"></textarea>

而且我有一个隐藏的输入字段可以跟随。

<input id="hiddenUserInput" />

textArea 包含如下值:

This is my friend @bingo_mingo and this is my another friend @lingo_tingo

隐藏字段字段包含相同的文本,但格式不同。

This is my friend @a142f2f0-1eda-11e3-ad5f-3c970e02b4ec:bingo_mingo and this is my another friend @a143edr0-1eda-11e3-ad5f-3c970e02b4ec:lingo_tingo

我希望这两个字段同步。每当我从真实文本区域中删除某些内容时,隐藏的内容都应该得到更新。此外,如果我开始删除正文中的 @admin_admin,隐藏的文本应该相应地更新。

是否有任何可用的 jquery 插件可用于此。

4

3 回答 3

1

我一个都没用过。你找过吗?这可能是一个: http: //github.com/ain/jquery-fieldsync 另外,这个问题是重复的:Synchonise 2 input fields, can it be done using jQuery?

于 2013-09-16T14:40:44.480 回答
1

.clone()从 Jquery使用。这很容易http://api.jquery.com/clone/

于 2013-09-16T14:43:05.640 回答
0

您可以创建一个侦听器,该侦听器将在更改时使用更新的文本更新隐藏字段。

$("#realAreaWhereUserTypes").bind("keyup paste", function() {
    var newStr = formatName($(this).val());
    $("#hiddenUserInput").val(newStr);
}); 

function formatName(str){
   // Do whatever change you need here.
}
于 2013-09-16T14:43:41.993 回答