function ToDefiniteURL(){
switch (document.all.strURL.value) {
case "1":
window.location.ref="1.htm";break;
case "2":
window.location.ref="2.htm";break;
default :
window.location.ref="3.htm";break;
}
}
<input type='text' name='strURL' onblur='javascript:ToDefiniteURL()'>
-----------
没测试
function tourl(e){
switch (e){
case "1":
location.href="1.html";
break;
case "2":
location.href="2.html";
break;
default:
location.href="3.html";
break;
}
}
</script>
<input type="text" name="url">
<input type="sbumit" value="提交" onclick="tourl('url.value')">
function tourl(e){
switch (e){
case "1":
location.href="1.html";
break;
case "2":
location.href="2.html";
break;
default:
location.href="3.html";
break;
}
}
</script >
<input type="text" name="url" >
<input type="submit" name="Button" id="Button" value="提交" onclick="tourl( 'url.value ')" />不管第一个文本框输入什么,点击后都转向3.html <script >
function ToDefiniteURL(){
switch (document.all.strURL.value) {
case "1":
window.location.ref="1.htm";break;
case "2":
window.location.ref="2.htm";break;
default :
window.location.ref="3.htm";break;
}
}
</script >
<input type= 'text ' name= 'strURL ' onblur= 'javascript:ToDefiniteURL() ' >点击后毫无反映。
改成:
window.location.href="1.htm";break;
注意红色部分.
onblur是失去焦点,文本框输入后要点一下空白处
function ToDefiniteURL(){
switch (document.all.strURL.value) {
case "1":
window.location.ref="1.htm";break;
case "2":
window.location.ref="2.htm";break;
default :
window.location.ref="3.htm";break;
}
}
</script >
<input type= 'text ' name= 'strURL ' onblur= 'javascript:ToDefiniteURL() ' >依然提示网页上有错误
function ToDefiniteURL(){
switch (document.all.strURL.value) {
case "1":
window.location.href="1.htm";break;
case "2":
window.location.href="2.htm";break;
default :
window.location.href="3.htm";break;
}
}
</script >
<input type= 'text ' name= 'strURL ' onblur= 'javascript:ToDefiniteURL() ' >IE 依然提示网页上有错误
function ToDefiniteURL(){
switch (document.all.strURL.value) {
case "1":
window.location.href="1.htm";break;
case "2":
window.location.href="2.htm";break;
default :
window.location.href="3.htm";break;
}
}
</script >
<input type= 'text ' name= 'strURL ' >
<input type="submit" name="Button" id="Button" value="提交" onclick="javascript:ToDefiniteURL() " / >还是提示网页上有错误
function tourl(e){
switch (e){
case "1":
location.href="1.html";
break;
case "2":
location.href="2.html";
break;
default:
location.href="3.html";
break;
}
}
</script >
<input type="text" name="url" >
<input type="submit" name="Button" id="Button" value="提交" onclick="tourl(url.value)" / >成功了,问题出在 onclick="tourl(url.value)" ;而不是onclick="tourl( 'url.value ')"
{
document.getElementById("btn1").onclick=function()
{
var val=document.getElementById(txtid).value;
window.location.href=val+".html";
}
}