首页 \ 问答 \ 当按下html键盘按钮时,将文本添加到输入字段(具有焦点的字段)(Add text to input fields (the one that has the focus) when html keyboard button pressed)

当按下html键盘按钮时,将文本添加到输入字段(具有焦点的字段)(Add text to input fields (the one that has the focus) when html keyboard button pressed)

我使用<div><a>标签在HTML中创建了一个屏幕键盘。 在页面上有六个文本输入(名字,昵称,姓氏,笔记,过敏,mobileNumber)。 我对JS并不擅长,但如果页面上只有一个输入,我知道该怎么做,但我不知道如何在有多个输入时执行此操作。 我一直在努力的部分是输入框在我点击一个字母后立即失去焦点。

如何将字母附加到选定的输入并且不会失去对该输入的注意力? 当它是页面上的唯一输入时,我使用这个函数将一个字母附加到一个输入:

var setClickEvents = function () {            
    $('.keyboard a.digit').unbind('click').click(function () {
        $name = $("input[id$='tbSearchBox']");
        $name.val($name.val() + $(this).html());
    });
}

HTML键盘按钮 - 只有一个字母,但它与所有字母和数字的样式/设置相同:

<a href="#" class="btn btn-default btn-lg digit">q</a>

I have created an on-screen keyboard in HTML using <div> and <a> tags. On the page there are six text inputs (firstName, nickname, lastName, notes, allergies, mobileNumber). I'm not that great at JS but I do know how to do it if there is just one input on the page but I'm not sure how to do it when there are multiple. Part of what I'm struggling with is the input box loses focus as soon as I click on a letter.

How do I append the letter to the selected input and not lose focus on that input? This is what I use to append a letter to one input when it is the only input on the page:

var setClickEvents = function () {            
    $('.keyboard a.digit').unbind('click').click(function () {
        $name = $("input[id$='tbSearchBox']");
        $name.val($name.val() + $(this).html());
    });
}

HTML keyboard button--just one letter but it is the same style/setup for all letters and numbers:

<a href="#" class="btn btn-default btn-lg digit">q</a>

原文:https://stackoverflow.com/questions/42798475
更新时间:2024-04-15 13:04

最满意答案

您不需要上下文。

由于Site.UpdateLinks正在创建属于该实例的 Link对象,因此该实例将与新Site关联。 添加到Site.LinksLink自动使新LinkSite具有相同的上下文(如果有)。 同样,当您保存SiteLink将随之保存。


You don't need the context for this.

Since Site.UpdateLinks is creating Link objects belonging to the instance, the instance will have associations with the new Site. Adding a Link to Site.Links automatically makes the new Link part of the same context (if any) as the Site. Likewise, when you save the Site the Link will be saved with it.

相关问答

更多
  • 假设底层数据库是MSSQL,这将比执行删除单个实体对象的任何事情都好得多。 foreach (var tableName in listOfTableNames) { context.ExecuteStoreCommand("TRUNCATE TABLE [" + tableName + "]"); } 当然,如果您的表具有外键关系,则需要按照正确的顺序设置表名列表,以便在清除所有可能依赖的主键表之前清除外键表。 This will perform much, much better than a ...
  • 我同意这些职位的一般想法。 ORM类模型首先是数据访问层的一部分(即使它由所谓的POCO组成)。 如果持久性与商业逻辑(或任何其他关切)之间出现任何利益冲突,则应始终作出有利于持久性的决定。 然而,作为软件开发人员,我们总是必须在纯粹主义和实用主义之间取得平衡。 是否将持久性模型用作域模型取决于多个因素: 开发团队的规模/一致性。 当整个团队知道属性可以公开,只是因为ORM要求,但不应该设置在所有的地方,这可能不是一个大问题。 如果每个人都知道(并遵守)ID属性不被用于业务逻辑,则ID可能不是很大的事情。 ...
  • 您不需要上下文。 由于Site.UpdateLinks正在创建属于该实例的 Link对象,因此该实例将与新Site关联。 添加到Site.Links的Link会自动使新Link与Site具有相同的上下文(如果有)。 同样,当您保存Site , Link将随之保存。 You don't need the context for this. Since Site.UpdateLinks is creating Link objects belonging to the instance, the instanc ...
  • 不要尝试设置Id,只需使用现有国家/地区实体创建新列表(并尽可能少地进行查询): var newList = new List(); foreach (HBCountry country in hbcampaign.HBTargetingSpec.HBCountries) { var countryMatch = db.HBCountries.FirstOrDefault(c => c.country_code == country.country_code) if ...
  • 出于同样的原因, partial类通常都存在,代码生成。 代码生成时; 你不希望你的额外的方法/属性/不管什么都消失,所以设计师将这些类标记为partial以允许用户将其他代码放入不同的文件中。 在Code-First中,EF的代码生成方面很大程度上已经过时,所以您创建的任何EF模型类都不需要partial 。 For the same reason partial classes typically exist at all, code generation. When code is generated ...
  • 您绝对可以在多个模型中共享POCO课程。 例如,像这样的类: public class Person { public int ID {get;set;} public string Firstname {get;set;} public string Surname {get;set;} public string Lastname {get {return Surname;} set {Surname = value;}} } 可以在EDMX中工作,将Person定义为ID,F ...
  • 莫滕,你是对的。 我必须创建一个EventTime对象的实例并将其分配给Event.EventTime。 那很有效。 我想这是不合理的,它不会自动为我做。 感谢你的评论。 Morten, you are right. I had to create an instance of the EventTime object and assign it to Event.EventTime. That worked. I guess it makes sense it wouldn't do it for me ...
  • 我过去使用Reflection来配对两个类似实体的属性。 我真的不知道有什么比循环类型的属性更好的方法,并将目标实体设置为源实体的值。 I've in the past used Reflection to pair up the properties of two like entities. I don't really know of any better way than to loop the Properties of the type and set the target entity to ...
  • 如果您对id使用简单的int ,则可以使用以下方法。 public abstract class BaseEntity { public int Id { get; set; } } public void AddOrUpdate (T entity) where T : BaseEntity { if(entity.Id > 0){ Entry(entity).State = EntityState.Modified; } else { Se ...
  • 我的问题是我试图通过原始ID设置关系,现在我明白必须用对象创建关系。 在上面的示例中,如果我想在MainCategory和SubCategory之间创建关系,我需要执行以下步骤: 创建mainCategory(将称为mainC)对象。 创建subCategory(将调用subC)对象。 设置subC.mainCategory = mainC; 感谢Gert Arnold。 My problem was that I tried to set the relationship by primitive Ids ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)