我想知道如何在字段中设置限制,例如,如果用户没有输入任何内容或仍然有空白字段,那么它不应该提交但显示*必填字段或类似的东西。例子很棒。
代码。我不知道从哪里开始
var fllname:TextField;
var address:TextField;
var ContactNo:TextField;
var quantity:TextField;
var otrack:TextField;
btnSubmit1.addEventListener(MouseEvent.CLICK, submit);
function submit(e:MouseEvent):void{
var urlvars: URLVariables = new URLVariables;
urlvars.fllname = fllname.text;
urlvars.Oadd = address.text;
urlvars.ContactNo = ContactNo.text;
urlvars.oquantiy = quantity.text;
urlvars.otrack = otrack.text;
urlvars.cake = txtCake.text;
urlvars.frosting = txtFrosting.text;
urlvars.topping = txtToppings.text;
urlvars.topping2 = txtToppings2.text;
urlvars.filling = txtFilling.text;
urlvars.amt = lblAmount.text;
var urlreq:URLRequest = new URLRequest("http://localhost/MCC/order.php");
urlreq.method = URLRequestMethod.POST;
urlreq.data = urlvars;
var loader : URLLoader = new URLLoader;
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(urlreq);
nextFrame();
}
答案 0 :(得分:0)
您可以使用enabled
参数来控制btnSubmit1
是否可点击,因此您可能需要先启用已停用。
btnSubmit1.enabled = false;
btnSubmit1.addEventListener(MouseEvent.CLICK, submit);
接下来,您需要在所有TextFields上收听TextEvent.TEXT_INPUT
事件
fllname.addEventListener(TextEvent.TEXT_INPUT,paramChanged);
address.addEventListener(TextEvent.TEXT_INPUT,paramChanged);
//etc etc
这会在用户更改其值时通知您,然后您可以创建单个函数(或每个控件的函数)来测试值,一旦它们通过您可以重新启用提交按钮。
function paramChanged(event:TextEvent):void
{
if (fllname.text != "" && address.text != "")//add your other fields here
{
btnSubmit1.enabled = true;
}
else
{
btnSubmit1.enabled = false;//If something changes that means we now fail the test you will want to disable the button again
}
}
您可以根据需要为每个字段制作自定义测试功能。