我的JavaScript代码是这样的:
$.ajax({ url:base_url+"agent_control/manage_booking/get_pax", type: "post", data: {id: id}, success:function(data) { App.unblockUI(); var code = JSON.parse(data); var isitable; var j; for(var i = 0; i < code.length; i++) { j = i + 1; isitable += '<tr>'; isitable += '<td>'+code[i].transactionpax_title+' '+code[i].transactionpax_firstname+' '+code[i].transactionpax_lastname+'</td>'; isitable += '<td><input type="text" id="tiket_number_'+i+'" class="form-control required" /></td>'; isitable += '</tr>'; } isitable += '<tr><td> </td><td><input type="button" value="Submit" class="btn blue dropdown-toggle submit_tiket_number" id="'+id+'" data="'+code.length+'" /></td></tr>'; $("#data_tiket_number").find("tbody").html(isitable); $('#data_tiket_number').modal('show'); } });
看这里 : <input type="text" id="tiket_number_'+i+'" class="form-control required" />
<input type="text" id="tiket_number_'+i+'" class="form-control required" />
我在文本输入中添加了必填项。但这不起作用如果文本输入为空,则当我单击“提交”时,不需要任何消息
有解决我问题的方法吗?
非常感谢你
您必须做三件事:
required
button
submit
查看演示- 小提琴
for(var i = 0; i < code.length; i++) { j = i + 1; isitable += '<tr>'; isitable += '<td>'+code[i].transactionpax_title+' '+code[i].transactionpax_firstname+' '+code[i].transactionpax_lastname+'</td>'; isitable += '<td><input type="text" id="tiket_number_'+i+'" class="form-control" required/></td>'; isitable += '</tr>'; } isitable += '<tr><td> </td><td><input type="submit" value="Submit" class="btn blue dropdown-toggle submit_tiket_number" id="'+id+'" data="'+code.length+'" /></td></tr>';