<script type ="text/jscript" > function checkFormat() { var total = document.getElementById("total").value; var num = document.getElementById("num").value ; if (total <= num * 7000 / 10000) {alert("金额不符合要求!");return false;} } </script><div> 请输入总金额:<input type ="text" id ="total"/><br /><br /> 请输入产品数量:<input type ="text" id ="num" /><br /> <asp:Button runat ="server" ID ="btn_OK" Text ="ok" OnClientClick ="return checkFormat();" /> </div>
function yanzheng() { var money = document.getElementById("金额的id"); var number = document.getElementById("数量的id"); if (money.value <= number.value * 7000 / 10000) { alert("不符合要求!") } } 然后用个事件调用这个方法就行了
你那textbox是服务器控件,要在服务器端验证
请输入总金额:<input type ="text" id ="total" onblur ="checkFormat()"/>
function checkFormat() {
var total = document.getElementById("total").value;
var num = document.getElementById("num").value ;
if (total <= num * 7000 / 10000) {alert("金额不符合要求!");return false;}
}
</script><div>
请输入总金额:<input type ="text" id ="total"/><br /><br />
请输入产品数量:<input type ="text" id ="num" /><br />
<asp:Button runat ="server" ID ="btn_OK" Text ="ok" OnClientClick ="return checkFormat();" />
</div>
我想在输入总金额之后就进行验证,不想再按下提交按钮后才进行验证,您看我这样写对吗?<asp:textbox id="tbPrice" runat="server" Width="120px" ontextchanged="checkFormat()"
></asp:textbox> 为什么一直报“并不包含checkFormat的定义”呢?
function yanzheng() {
var money = document.getElementById("金额的id");
var number = document.getElementById("数量的id");
if (money.value <= number.value * 7000 / 10000) {
alert("不符合要求!")
}
}
然后用个事件调用这个方法就行了
<asp:TextBox runat ="server" ID ="total" ></asp:TextBox>protected void Page_Load(object sender, EventArgs e)
{
total.Attributes.Add("onblur","checkFormat()");
}