免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3255 | 回复: 3
打印 上一主题 下一主题

window.location 的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-10-03 21:57 |只看该作者 |倒序浏览
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
//请问:
//为什么javascript function 中window.location 之前有var idv=document.getElementById('t1').value一行
//就不正确运行?

//还有如果改成onClick="window.location='http://www.google.com';checkt1();"
//而onClick="checkt1();window.location='http://www.google.com';"
//就不能够正确运行?(仅仅在onClick中换了一个次序)

</HEAD>
<BODY>

<P><input name ='t1' id= 't1' value="SGR07"></P>
<br>
        <a href="" onClick="checkt1();">Sample Link</a>
       
<script type="text/javascript" language="JavaScript"><!--

function checkt1(){
var idv=document.getElementById('t1').value;
//alert(" value is "+idv);
window.location='http://www.google.com';
//=window.document.getElementById('t1').value'
}

function gotourl(){
window.location='http://www.google.com';
}
        //-->
</script>

论坛徽章:
0
2 [报告]
发表于 2006-10-03 22:23 |只看该作者

另外一些奇怪的事在javascript中

如果把第A行和第B行屏蔽掉任意一个,窗口就不能正确导向www.google.com
<P><input name ='t1' id= 't1' value="SGR07"></P>
<a href="" onClick="gotourl(); checkt1();">Sample Link</a>       
<script type="text/javascript" language="JavaScript"><!--

function checkt1(){
idv=document.getElementById('t1').value;  // 第A行
alert(" value is "+idv);                                 //第B行
//window.location='http://www.google.com';
//=window.document.getElementById('t1').value
//window.navigate("http://www.google.com");
//location.reload();
//=window.document.getElementById('t1').value'
}

function gotourl(){
window.location='http://www.google.com';
}

论坛徽章:
0
3 [报告]
发表于 2006-10-03 22:34 |只看该作者

总之行CBA这个顺序才行,如果ABC就不行

window.location="http://www.google.com"; //C
idv=document.getElementById('t1').value;  //A
alert(" value is "+idv); //B

论坛徽章:
0
4 [报告]
发表于 2006-10-03 22:44 |只看该作者

其实我的目的是需要用到idv,转到下面的目标URL(含有来自文本框值的参数)

<script type="text/javascript" language="JavaScript"><!--

function checkt1(){
idv=document.getElementById('t1').value;
alert(" value is "+idv);
//window.location="http://www.google.com";
//目标URL:
window.location="http://www.myweb.com/hse/?action=SUBSCRIPTION
&amp;term_country=USA&amp;sub_type=GIFT&amp;promo_code=idv";
}
</script>
<P><input name ='t1' id= 't1' value="SGR07"></P>
<a href="" onClick="checkt1();">Sample Link</a>
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP