【发布时间】:2014-09-04 15:26:15
【问题描述】:
我现在正尝试在成功完成 ajax 请求后重置文本框的值。 我试过这样的东西
$('#text1').val("");
$('#text2').prop('value','');
但不会工作。 这些都在控制台中工作..
<script type="text/javascript" src="/Includes/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$('#btn').click(function(){
jQuery.ajax({
url:"validation.cfc",
data:{method:'db_validation',fname:$('#text1').val(),Email:$('#text2').val()},
type:"POST",
success:function(html){
//what code should be written to clear textbox values after successful ajax response
//$('#text1').val(""); ---> This code was not working
$('#para').html(html);//even this code was executed.
}
});
});
});
</script>
<form>
<p id="para"></p>
<input id="text1" name="txtBox1" type="text"><br />
<input id="text2" name="txtBox2" type="text"><br />
<input type='button' name='Button' value='Add User' id="btn"/>
</form>
【问题讨论】:
-
你有多少个id为
text1的元素? -
我更新了我的答案并添加了一个小提琴示例。很抱歉发表评论,我不知道您是否了解答案编辑