有没有一种方法可以使以下代码在同一页面上显示链接,而不是打开新页面上的链接?例如,如果我在文本字段中编写“project”并按下提交按钮,则 project.htm 链接将显示在页面上;如果我在文本框中写下“under”并按下提交按钮,则 underconstruction.htm 链接变为可见。
<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>
答案 0 :(得分:0)
不确定这是否是一个技巧问题..你不能这样做吗?
<强>脚本强>
if (text_form.text_name.value == "project")
document.getElementById('project_link').style.display = 'block';
else if (text_form.text_name.value == "under")
document.getElementById('construction_link').style.display = 'block';
else
alert("Invalid keyword!");
return (false);
<强>标记强>
<a id='project_link' href='project.htm' style='display: none;'>project</a>
<a id='construction_link' href='underconstruction.htm' style='display: none;'>construction</a>