English 中文(简体)
通用 Java印功能,可使用超文本和Asp.net控制?
原标题:Generic JavaScript function to access HTML and Asp.net Control?

是否可能写出一个单管功能,通过背书获得元素

i tried to use this function

function getEleById(ele,IsServerElemt) {
      var elmt ;
      if(IsServerElemt) 
          elmt  =  <%= + ele +  .ClientID%>  ;
      else 
          elmt = ele;

      return document.getElementById(elmt);
}

在此,我们有超文本和Asp.Net文本Box。

<input type="text" id="txtname" />

<asp:TextBox ID="txtname" runat="server"></asp:TextBox>

iam试图称职如下:

var name = getEleById( txtname ,true) ;

这里的确具体规定,txt 名称是服务器控制

是否可能采用通用的javascript方法进行超文本控制以及App.Net控制。

希望得到任何帮助。

增 编

问题回答

创建你们的文本箱。

<asp:TextBox ID="txtname" runat="server"></asp:TextBox>

您可以查阅。

var textbox= $find("<%=txtname.ClientID %>");

如何使用JQuery S CSS的甄选者?

1) $( .txtName ) //JQuery CSS selector

iii

<asp:TextBox ID="txtname" class="txtName" runat="server"></asp:TextBox>

您可在外部联合材料中以这种方式提供全部文字。 JQuery CSS 选任

可查阅,这一条。 它解释了产生要素识别特征的各种途径。

我所做的事情是创造我的文本箱,如:

<asp:TextBox ID="txtname" runat="server" ClientIDMode="Static" />

Setting the ClientIDMode to static will set the rendered ID to exactly what you type in the Asp.Net markup. It will render out as something like this:

<input id="txtname" name="?????" />

那么,你的 j脚本可以照此写:

function getEleById(elementID) {
    return document.getElementById(elementID);
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签