<script language=javascript>
function check()
{
if ((document.frm.str1.value)!=(document.frm.str2.value))
{
alert("不相等")
document.frm.str1.focus()
}
else
document.frm.submit()
}
</script>
<form name=frm action="doit.jsp">
<input type=text name=str1>
<input type=text name=str1>
<input type=button onclick="check()">
</form>

解决方案 »

  1.   

    <input type=text name=str1>
    <input type=text name=str1>
    应该是
    <input type=text name=str1>
    <input type=text name=str2>
      

  2.   

    <input type=button value="submit" onclick="check()">
      

  3.   

    谢谢!谢谢!您的程序很好!
    但是,我原来是想用jsp对字串做一些处理的,因为我要的是一个产品名与对应的产品名的文件名,比如:产品(电视机),文件名(电视机.doc)
    //产品的文件名要对应产品是我们已经规定好的!
    我原来是用jsp取得文件名的前部分(比如 电视机.doc在点前的部分),但您的程序则只好使用javascript做处理了,不知您能否帮忙帮到底?!
    另外,您所提供的程序好象只有一个确认按钮,没有取消的呀?!麻烦您了!
      

  4.   


    function check()
    {
    if ((document.frm.str1.value)!=(document.frm.str2.value))
    if(confirm("不相等,重新填写"))
    document.frm.str1.focus()
    else
    document.frm.submit()
    }
      

  5.   

    我想你可以用,subString()方法来截取点以前的String.可以用jsp来实现