文本框使用 if else 语句打开我的链接 JavaScript
textbox opening my link using if else statement javascript
我想要完全相同的东西,但否则它将打开我另一个.htm文件的链接。 整个代码很好,但是当我在textfeld中输入某些内容时,我希望在警报或主窗口中出现一个链接。
<script Language="JavaScript">
<!--
function Blank_TextField_Validator() {
// Check the value of the element named text_name from the form named text_form
if (text_form.text_name.value == "") {
// If null display and alert box
alert("Please fill in the text field.");
// Place the cursor on the field for revision
text_form.text_name.focus();
// return false to stop further processing
return (false);
}
// If text_name is not null continue processing
return (true);
}
-->
</script>
<form name="text_form" method="get" action="#" onsubmit="return Blank_TextField_Validator()">
<input type="text" name="text_name" >
<input type="submit" value="Submit">
</form>
但在其他情况下,它将打开我另一个.htm文件的链接。
"否则"的意思是在表单提交返回 true 时打开链接?如果是这样,只需将链接放在表单的 action
属性中,而不是 #
。
但是当我在文本中输入某些内容时,我希望出现一个链接 在警报中或在主窗口中。
如果要显示显示链接的消息,请在// If text_name is not null continue processing
后加上alert('www.example.com');
。
编辑
我调整了你的JS函数:
<script Language="JavaScript">
<!--
function Blank_TextField_Validator() {
// Check the value of the element named text_name from the form named text_form
if (text_form.text_name.value == "") {
// If null display and alert box
alert("Please fill in the text field.");
// Place the cursor on the field for revision
text_form.text_name.focus();
// return false to stop further processing
return (false);
}
// If text_name is not null continue processing
if (text_form.text_name.value == "project")
window.open('project.htm');
else if (text_form.text_name.value == "under")
window.open('underconstruction.htm');
else
alert("Invalid keyword!");
return (true);
}
-->
</script>
相关文章:
- 我的下拉菜单中的链接不起作用
- 我的链接按钮的OnClick事件永远不会被触发
- 值更改我的链接而不更新
- 使浏览器为我的链接添加书签
- 为什么我的链接不会触发jQuery.click事件
- 为什么我的JS为我的链接添加前缀(localhost:3000 / mylink)
- 文本框使用 if else 语句打开我的链接 JavaScript
- Tumblr将新代码注入我的链接中
- Javascript函数正在删除我的链接中的属性
- 如何在外部域名中查找我的链接
- 为什么我的链接处于不同的高度
- 如何让我的链接打开“弹出窗口”
- 如何将我的链接获取到变量中
- 我应该在哪里添加JS事件,使我的链接工作
- 为什么我的链接没有在我的网页的移动版本遵循
- 当我点击我的链接时,我调用我的对话框,但对话框没有出现
- 为什么告诉jQuery点击我的链接按钮会减慢我的页面速度?
- 如何使我的工具提示出现在我的链接下面,即使我的链接在页面的底部
- 我的链接使用 jquery 无法正常工作
- 如何使我的链接打开菜单与列表项的id,我想要访问