HTML代码 文本框、按钮 文本框中输入“123”点击按钮转入1.html 文本框内容是其他字符,转入2.html

HTML代码文本框、按钮文本框中输入“123”点击按钮转入1.html文本框内容是其他字符,转入2.html... HTML代码 文本框、按钮 文本框中输入“123”点击按钮 转入1.html
文本框内容是其他字符,转入2.html
展开
 我来答
系统004
2012-03-08 · TA获得超过3254个赞
知道大有可为答主
回答量:1326
采纳率:68%
帮助的人:1178万
展开全部
<html>
<head>
<title>无标题页</title>
<script type="text/javascript">

function btnclick() {
var textValue = document.getElementById("text").value;
if (textValue = "123") {
document.location = "1.html";
}
else {
document.location = "2.html";
}
}

</script>
</head>
<body>
<input type="text" id="text" /><input type="button" value="点击" id="btn" onclick="btnclick()" />
</body>
</html>

注释:上面就是实现的方法,1.html和2.html你可以自己写内容然后更改JS里面的那个地址就可以,这里只给你写怎么验证和跳转。希望采纳。
追问
不输入 123 也会跳转到1.html
追答
就是啊,你不是就是要求输入123跳转到1.html,什么也不输入则跳转到2.html吗? 你想排除字符串的话,可以在修改成

function btnclick() {
var textValue = document.getElementById("text").value;
if (textValue = "123") {
document.location = "1.html";
}
else if(textValue !="123" && textValue!="") {
document.location = "2.html";
}
}
这样既可。
molaifeng
2012-03-11 · TA获得超过5273个赞
知道大有可为答主
回答量:1629
采纳率:50%
帮助的人:1815万
展开全部
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<title>跳转网页</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<script type="text/javascript">
function leave() {
if (document.getElementsByName('wenben')[0].value=='123') {
window.location.href="1.html";
} else {
window.location.href="2.html";
}
}
</script>

<style type="text/css">
</style>
</head>
<body>
<p><textarea name="wenben"></textarea></p>
<p><input type="button" value="测试" onclick="leave();"></p>
</body>
</html>
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
箫幽zmx
2012-03-09
知道答主
回答量:1
采纳率:0%
帮助的人:1673
展开全部
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式