如何将值从参数传递到javascript中的标签? [英] how to pass value from params to a label in javascript ?

查看:69
本文介绍了如何将值从参数传递到javascript中的标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试将一些值从HTML传递到HTML,而不使用后面的代码.我有一个Java脚本的功能,可以完成工作,但是却不如我所愿.我希望从一页到第二页的值可以存储并显示在标签中,而不是在HTML页上公开地写它,但我不能这样做.谁能告诉我我要去哪里错了?
这是我的代码:

Hi,
I am trying to pass some values from HTML to HTML without using code behind. I have a function of java script which do the work but not as I want. I want that the values coming from one page to second, can be stored and shown in label instead of openly writing it on HTML page and I am not able to do so. Can anyone please tell me where am I going wrong ?
Here is my code:

params = getParams();
firstname = unescape(params["firstname"]);
lastname = unescape(params["lastname"]);
age = unescape(params["age"]);
document.write("firstname = " + firstname + "<br>");
document.write("lastname = " + lastname + "<br>");
document.write("age = " + age + "<br>");
var lbl = document.getElementById('<%=lbl.ClientID%>');
lbl.innerHTML=firstname.



这是第二页上的我的html代码:



and this is my html code on second page:

<form id="form1" runat="server">
<asp:Label ID="lbl" runat="server" Text="Label"></asp:Label>
   </form>

"



这是我在第一页上的代码:

"



and here is my code on first page:

<form type=get action="second.aspx">
<table>
<tr>
<td>First Name:</td>
<td><input type="text" name="firstname" size="10"></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type="text" name="lastname" size="10"></td>
</tr>
<tr>
<td>Age:</td>
<td><input type="text" name="age" size="10"></td>
</tr>
<tr>
<td colspan=2><input type="submit" value="Submit">
</td>
</tr>
</table>
</form>

推荐答案

此浏览器特定问题.试试这个
This browser specific issue. Try this
var lbl = document.getElementById('<%=lbl.ClientID%>');
if(lbl !=null)
{
lbl.innerHTML=firstname;
lbl.innerText=firstname;
lbl.textContent =firstname;
}


这不是客户端任务.
这是服务器端任务(IMHO).
因此,例如使用PHP.
This is not client side task.
This is server side task (IMHO).
So use for example PHP.


这篇关于如何将值从参数传递到javascript中的标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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