我已经构建了一些输入来让用户搜索数据库。搜索使用ajax请求。
我遇到的问题是因为当我收到服务器的响应时,我也收到了搜索输入。我不想这样。
看看我的代码:.
<script>
$(document).on('change', '.auto-select', function(e){
e.preventDefault();
var tags = $('#auto-tag-script').serialize();
var contracts = $('#auto-contract-script').serialize();
var educations = $('#auto-education-script').serialize();
var towns = $('#auto-town-script').serialize();
runAjax(tags, contracts, educations, towns);
});
function runAjax(tags, contracts, educations, towns) {
$.ajax({
url: 'http://localhost/jobs/public/anazitisi-ergasias?' + tags + '&' + contracts + '&' + educations + '&' + towns
}).done(function(data){
$('div.show-html-from-ajax').html(data);
});
}
</script>
使用上面的代码,输入再次出现在我的页面中。
有什么办法可以转义这个表单输入吗?
最佳答案
您可以通过两种方式隐藏它......在插入之前(最佳方式)或插入之后
$.ajax({
url: '...'
}).done(function(data){
// create jQuery object from response
var $html = $(data);
//hide within that object
$html.find('.search-form-for-hide').hide();
// insert the object
$('div.show-html-from-ajax').html($html);
/******* OR ***************/
// the html is in the DOM now, can do whatever might be needed to it
$('.search-form-for-hide').hide();
});
对于许多插件,您需要先插入然后调用插件
关于javascript - 在 $.ajax 调用后删除特定输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33024081/