站内搜索: 请输入搜索关键词

当前页面: JAVA 编程资料牛鼻论坛AJAX & JavaScript 技术→javascript脚本问题

javascript脚本问题

发表新主题   回复此主题

第1楼 2006-12-30 11:02 wlm_007_007_03 写道:

javascript脚本问题


页面a.asp里面有个表单名字form1,表单里面有个<input maxlength=20 size=20 name="Country" id="Country">

点击了a.asp上的一个链接而打开了b.asp(窗口),又转向一个c.asp页面.
我通过c.asp里面的一个连接,给a.asp里面的Country负值.可是怎么也不行,总是说找不到对象.晕啊~~~~~~!!!
帮我看看!!!
c.asp
------------------------------------------------
<script language="javascript">
function selectok(pk1){
var pk1
window.parent.opener.form1.Country.value=pk1;
window.parent.close();
}
</script>

<a href="#" onClick="selectok(1)">谢谢帮助</a>

-------------------------------------------------------
错误信息是:window.parent.opener.form1.Country为空或找不到对象,
明明a.asp里面有Country这个对象啊!!!怎么就说没有呢???而且c.asp这个窗口也是a.asp创建的啊!!!实在搞不明白.

第2楼 2013-08-31 12:44 Robot :

javascript脚本问题 相关


第3楼 2006-12-30 11:23 菲珑 写道:

在ASP。NET里面怎么调用JAVASCRIPT脚本?我没有弄清楚搂住的意思。一般的ASP.NET的后台程序是运行在服务器上的,JS是运行在客户端的IE的,所以是无法直接调用的。
可以使用页面输出的方式使ASP.NET调用JS,就是在ASP.Net里面加上直接输出调用JS的脚本。
还可以使用XMLHTTP的方式用JS请求ASP.NET,然后由ASP.NET输出有意义的XML文本,再由JS解析这些文本来执行相应的JS函数。AJAX就是这个思路
<%@ Page language="c#" Codebehind="user_login.aspx.cs" AutoEventWireup="false" Inherits="haogg.user_login" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD> <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<LINK href="css/user.css" type="text/css" rel="stylesheet">
<script language="javascript">
function checkEmpty()
{

if(Form1.all.Textbox1.value=="")
{
alert("请输入用户名!");
return false;
}
else if(Form1.all.Textbox2.value=="")
{
alert("请输入密码!");
return false;
}
else
{
return true;
}
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">



<table style="BORDER-COLLAPSE: collapse" cellSpacing="0" cellPadding="0" width="80%" align="center"
border="1" background="images/1.gif">
<tr>
<td vAlign="top" colSpan="2" height="25"> <span style="FONT-WEIGHT: bold; FONT-SIZE: 18px">用户登录</span>
</td>
</tr>

<tr>
<td width="15%" height="30"> 用户名:</td>
<td><asp:TextBox id="Textbox1" runat="server" width="198px"></asp:TextBox>
</td>
</tr>
<tr>
<td style="HEIGHT: 27px" width="15%" height="27"> 密码:</td>
<td style="HEIGHT: 27px">
<asp:TextBox id="Textbox2" runat="server" width="199px" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr height="20">
<td borderColor="#ffffff" colSpan="2"></td>
</tr>
<tr>
<td></td>
<td><input id="Submit1" type="submit" size="20" value=" 登陆 " name="B1" runat="server">
</td>
</tr>
</table>
</form>
</body>
</HTML>


第4楼 2006-12-30 17:10 Vampire 写道:

还是用document.getElementById(“Country”).value吧,这个能拿到属性值。
以下摘自MSDN
getElementById Method

--------------------------------------------------------------------------------

Returns a reference to the first object with the specified value of the ID attribute.

Syntax

oElement = document.getElementById(sIDValue)
Parameters

sIDValue Required. String that specifies the value of an ID attribute.

Return Value

Returns the first object with the same ID attribute as the specified value.

Remarks

If the ID value belongs to a collection, the getElementById method returns the first object in the collection.

Example

This example uses the getElementById method to return the first occurrence of the ID attribute value, oDiv.

<SCRIPT>
function fnGetId(){
// Returns the first DIV element in the collection.
var oVDiv=document.getElementById("oDiv1");
}
</SCRIPT>
<DIV ID="oDiv1">Div #1</DIV>
<DIV ID="oDiv2">Div #2</DIV>
<DIV ID="oDiv3">Div #3</DIV>
<INPUT TYPE="button" VALUE="Get Names" onclick="fnGetId()">


参考资料:
MSDN

发表新主题   回复此主题