代码如下,如果文本框不填,根据js里的方法会弹出提示,但是点了对话框的确定以后,程序还是进action了。如何不让他进action呢
function getText()
{
var m_New = document.getElementById('m_New').value;
if(m_New=="")
{
alert("请输入新车价格");
document.form1.m_New.focus();
return false;
}
return true;
} <body>
<s:form action="computeCnav" namespace="/cnav" id="form1" validate="true">
新车价格:<input type="text" name="m_New" style="width:97" />万元<br>
<input type="submit" value="确定" OnClick="getText();" />
</s:form>
</body>
function getText()
{
var m_New = document.getElementById('m_New').value;
if(m_New=="")
{
alert("请输入新车价格");
document.form1.m_New.focus();
return false;
}
return true;
} <body>
<s:form action="computeCnav" namespace="/cnav" id="form1" validate="true">
新车价格:<input type="text" name="m_New" style="width:97" />万元<br>
<input type="submit" value="确定" OnClick="getText();" />
</s:form>
</body>
{
var m_New = document.getElementById('m_New').value;
if(m_New=="")
{
alert("请输入新车价格");
document.form1.m_New.focus();
return;
} } <body>
<s:form action="computeCnav" namespace="/cnav" id="form1" validate="true">
新车价格:<input type="text" name="m_New" style="width:97" />万元<br>
<input type="submit" value="确定" OnClick="getText();" />
</s:form>
</body>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js校验</title>
</head>
<script language="javascript">
function getText()
{
var m_New = document.getElementById('m_New').value;
if(m_New==""||m_New==null)
{
alert("请输入新车价格");
document.form1.m_New.focus();
return false;
}
return true;
}
</script>
<body>
<s:form action="computeCnav" namespace="/cnav" id="form1" validate="true">
新车价格:<input type="text" name="m_New" style="width:97" />万元<br>
<input type="submit" value="确定" OnClick="getText();" />
</s:form>
</body>
</html>
对着啊
行不
function getdText(){
var m_New = document.getElementById("m_New").value;
if(m_New==""){
alert("请输入新车价格");
document.form1.m_New.focus();
return false;
}
return true;
}
</script>
</head><body> <s:form action="computeCnav" namespace="/cnav" name="form1" id="form1" validate="true">
新车价格:<input type="text" name="m_New" id="m_New" style="width:97px" />万元<br>
<input type="submit" value="确定" onclick="return getdText()"/>
</s:form></body>
<form ..... onSubmit="return getText();">
....
<input type="submit" value="确定"/>
</form>