想要访问字面值到javascript [英] Want to access literal value into javascript

查看:147
本文介绍了想要访问字面值到javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文字控制页面(有一些数据)。我想在JavaScript中访问它,并想要放一些文本。请告诉我如何在JavaScript中访问文字控制。我尝试使用以下代码 -

I have got a literal control on page (with some data on it). i want to access it in javascript and want to put some text on it. please tell me how can i access literal control in JavaScript. I was trying with following code-

<asp:Literal  ID="lblPerInstanceListing" runat="server"></asp:Literal>

Javascript:

Javascript:

 var value= document.getElementById('<%=lblPerInstanceListing.ClientID %>')


$ b b

我得到空值返回。

I am getting null value return by this.

推荐答案

ASP.NET Literal控件本身不插入任何HTML到网页。

An ASP.NET Literal control does not by itself insert any HTML into a webpage. Your Literal control is a placeholder for text or HTML you will set in your code behind.

您应该将文字封装在DIV或SPAN中,并赋予ID和引用JavaScript中的DIV或SPAN

You should wrap your literal in a DIV or SPAN and give that an ID and reference that DIV or SPAN in the JavaScript

WebForm:

<span id="yourId"><asp:Literal  ID="lblPerInstanceListing" runat="server"></asp:Literal></span>

JavaScript:
由此代码解决。 >

JavaScript: Solved by this code.

var value= document.getElementById('yourId').innerText;

这篇关于想要访问字面值到javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆