如何将焦点设置为webForm的控件 [英] How to set Focus to the Controls of webForm
问题描述
代码:
Code:
else if (answer is HandwrittenAnswer)
{
this.Sourcecode.AppendLine("\t\t\t\t<textarea id='" + id + "' name='" + id + "' value='' style='position: absolute; "
+ "top: " + top + "px; left: " + left + "px; height: " + height + "px; width: " + width + "px; "
+ "visibility: hidden; z-index: 2; resize: none;'></textarea>");
this.Sourcecode.AppendLine("\t\t\t\tdocument.getElementById (" + id + ").focus();");
}
上面的代码,当我点击我的网页表单时,它会创建一个控件。当我点击它时,它会创建一个控件(一个盒子),我可以写手写,但是在这里写东西控制我需要再次点击因为没有焦点,我的代码的第一行创建一个控件现在我想设置一个焦点,这样当我点击它我可以直接写一些东西怎么做,因为我试过第二行
this.Sourcecode.AppendLine(\t\t\t\tdocument.getElementById(+ id +)。focus(););
但似乎没有工作,而是整行写在我的网络表格顶部..
??? Anybo有一个解决方案???
with above code when i click on my web form it creates a Control. When i click firsttly it creates a control(a box) where i can write handwritten, but to write something in this control i need to click again because there is no focus ,first line of my code create a control now i want to set a focus so that when i click in it i can write something directly how to do it, for that i tried second line
this.Sourcecode.AppendLine("\t\t\t\tdocument.getElementById (" + id + ").focus();");
but it seems not working instead whole line is written on the Top of my webform..
??? Anybody got a solution???
推荐答案
试试这个。我已将声明放在脚本标记中。
Try this. I have placed the statement with in the script tag.
this.Sourcecode.AppendLine("<script>\t\t\t\tdocument.getElementById (" + id + ").focus();</script>");>
这篇关于如何将焦点设置为webForm的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!