当按下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
最满意答案
您不需要上下文。
由于
Site.UpdateLinks
正在创建属于该实例的Link
对象,因此该实例将与新Site
关联。 添加到Site.Links
的Link
会自动使新Link
与Site
具有相同的上下文(如果有)。 同样,当您保存Site
,Link
将随之保存。You don't need the context for this.
Since
Site.UpdateLinks
is creatingLink
objects belonging to the instance, the instance will have associations with the newSite
. Adding aLink
toSite.Links
automatically makes the newLink
part of the same context (if any) as theSite
. Likewise, when you save theSite
theLink
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 ...
-
合并实体框架中的实体(Merging entities in Entity Framework)[2020-02-25]
我过去使用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 ... -
实体框架5 - 在插入Db之前在实体之间创建关系(Entity Framework 5 - Create realationships between entities before inserting to Db)[2022-09-10]
我的问题是我试图通过原始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 ...