我想将具有绝对位置的div放在屏幕视图的中心(滚动或不滚动).
我有这个但它的位置div在文档中间而不是当前视图的中间.
#main {
width: 140px;
height:100px;
border: 1px solid Black;
text-align: left;
position: absolute;
top: 50%;
left: 50%;
margin-left:-70px;
margin-top:-50px;
}
Run Code Online (Sandbox Code Playgroud) 我想替换所选文本(如果没有选择任何内容,则在光标位置后插入新文本).新文本从另一个文本框输入.
我希望能够插入新文本而不先在textarea中单击(聚焦).
含义:首先选择要在textarea中替换的文本,然后在文本框中输入新文本并单击按钮.
<textarea id='text' cols="40" rows="20">
</textarea>
<div id="opt">
<input id="input" type="text" size="35">
<input type="button" onclick='pasteIntoInput(document.getElementById("input").value)' value="button"/>
</div>
function pasteIntoInput(text) {
el=document.getElementById("text");
el.focus();
if (typeof el.selectionStart == "number"&& typeof el.selectionEnd == "number") {
var val = el.value;
var selStart = el.selectionStart;
el.value = val.slice(0, selStart) + text + val.slice(el.selectionEnd);
el.selectionEnd = el.selectionStart = selStart + text.length;
}
else if (typeof document.selection != "undefined") {
var textRange = document.selection.createRange();
textRange.text = text;
textRange.collapse(false);
textRange.select();
}
}
Run Code Online (Sandbox Code Playgroud)
在线示例: 链接文本
数据库中的"类别"表定义如下:
CategoryID - PK ,identity specification ON (only this column has identity)
Description
Title
Run Code Online (Sandbox Code Playgroud)
我想插入新数据:
Category cat = new Category
{
Description = "xxx",
Title = "yyy",
};
if (cat.EntityState == EntityState.Detached)
{
Articlerctx.AddToCategories(cat);
}
return Articlerctx.SaveChanges();
Run Code Online (Sandbox Code Playgroud)
我收到错误:
当IDENTITY_INSERT设置为OFF时,无法在表'Categories'中为identity列插入显式值.
但我没有插入CategoryID!我希望它能获得自动价值!
如何在泛型方法中访问对象的属性?
我无法使用,where T: A因为此方法将接收不同的对象,但所有对象都有一个共同的属性来处理.
(我也不能为他们制作一个通用界面)
public class A
{
public int Number {get;set;}
}
List<A> listA = new List<A>{
new A {Number =4},
new A {Number =1},
new A {Number =5}
};
Work<A>(listA);
public static void Work<T>(List<T> list1)
{
foreach(T item in list1)
{
do something with item.Number;
}
}
Run Code Online (Sandbox Code Playgroud)
更新:我还需要设置属性