如何在 html 中创建文本框,如 Outlook To(收件人姓名)

How to create a textbox like Outlook To (names of the recipients) in html

本文关键字:To 收件人 Outlook html 文本 创建      更新时间:2023-09-26

我需要创建一个文本框控件,如 Outlook To .基本上我需要输入一些用分号分隔的用户名,Ctrl K(或按钮单击(将验证用户是否喜欢在 Outlook 中。

任何人都可以在这里帮忙。

提前谢谢。

这是一个非常快速和肮脏的例子,你可以尝试什么,显然可以进行改进,但在大多数情况下会发生这样的事情。

// list of possible matches
var names = ['john', 'ben', 'dylan', 'kelly', 'beth']
// on form submission
$('form').on('submit', function(){
  // get the input
  var text = $('input[type=text]').val()
  var match = text;
  
  // check each name
  names.forEach(function(e,i){
    // check if the name matches
    if(e.indexOf(text) > -1) {
      // found a match, set it
      match = e
    }
  })
  // update the input
  $('input[type=text]').val(match)
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
  <input type="text">
  <input type="submit" value="Validate">
</form>