我有一个带angularjs代码的php表单。初始屏幕看起来像 Before submit
用户提交表单后,我想清空所有字段,但是下面的代码似乎并不对字段执行此操作,而对按钮却如此。
之前 后 形式和代码如下,我尝试空白电子邮件字段。按钮已更改,因此我知道它会通过angularjs代码进行处理。
<!-- Contact Section Angularjs -->
<div id="myapp" ng-controller="contacts_empcontroller">
<div id="contact" class="w3-container w3-padding-16" >
<h3 class="w3-border-bottom w3-border-light-grey w3-padding-16">Contact</h3>
<form id="contact_02" >
<p><h4> If you would like to book an event or conference please contact us.</h4></p>
<p ng-bind="msg1"></p>
<input id="name1" class="w3-input w3-section" type="text" placeholder="Name" required name="Name" value=" " ng-model="name1">
<input id="email1" class="w3-input w3-section" type="text" placeholder="Email" required name="Email" value="" ng-model="email1">
<input id="subject1" class="w3-input w3-section" type="text" placeholder="Subject" required name="Subject" value="" ng-model="subject1">
<input id="comment1" class="w3-input w3-section" type="text" placeholder="Comment" required name="Comment" value="" ng-model="comment1">
<input id="token1" class="w3-input w3-section" type="hidden" name="token1" value="<?php echo $token;?>" >
<button class="w3-button w3-black w3-section" ng-click="postData()" id="buttoncontact" >Send Message</button></p>
</form>
</div>
</div>
Angularjs代码
if (data.success == "ip_over_2")
{
document.getElementById("buttoncontact").innerHTML = "Duplicate - Thanks";
document.getElementById("email1").innerHTML = "-";
}
感谢您的帮助
第二种形式
<div class=" col-sm-4 ">
<div id="myapp" ng-controller="subscribe_controller">
<h4 style="color:black;" >Subscribe To Newsletter</h4>
<form id="subscribe_01">
<h4>
<p ng-bind="msg2"></p>
<input id="email2" style="color:gray;" type="text" name="EMAIL" placeholder="Your Email Adddress" value="" ng-model="email2" required ></h4>
<input id="token2" class="w3-input w3-section" type="hidden" name="token2" value="<?php echo $token;?>" >
Enter Code: <font size="3" color="blue"><?php echo $captcha_token;?> </font>  
<input id="captcha" type="text" placeholder="Code" name="captcha" value="" ng-model="captcha" size="10" required>
<p><p>
<button class="w3-button w3-black" ng-click="postData_subscribe()" id="buttoncontact_subscribe">Send To Subscribe</button></p>
</form>
</div>
答案 0 :(得分:0)
只需执行以下操作即可代替document.getElementById("...").innerHTML;
:
$scope.name1 = '';
$scope.email1 = '';
$scope.subject1 = '';
$scope.comment1 = '';
这将使用指定的值更新模型(ng-model="email1"
),在这种情况下,将使用空白值(以您指定的目标为目标)。