gpt4 book ai didi

php - 为什么点击标签后,页面刷新并且appendTo不起作用?

转载 作者:行者123 更新时间:2023-11-28 16:29:19 25 4
gpt4 key购买 nike

标签a是$.each()。看我的js代码:

 $('.auto_complete').keyup(function () {
var id = '#' + this.id;
var alt = $(id).attr('alt'); var id = $(this).attr('id'); var name = $(this).attr('name');
var url = alt + id + '/' + name;
var dataObj = $(this).closest('form').serialize();
$.ajax({
type: "POST",
url: url,
data: dataObj,
cache: false,
dataType: 'json',
success: function (data) {
$(".list_name").show().html('');
$.each(data.name, function(a,b){
$(".list_name").append('<p><a href="" id="result">' + b + '</a></p>');
////////////////////here/////////////////////
$('.list_name p a').live('click', function(e) {
e.preventDefault();
$('<b>' + b + '، </b><input type="text" name="hotel[]" value="' + b + '" style="border: none; display: none;" />').appendTo('.auto_box span');
$(this).remove();
return false;
});
/////////////////////////////////////////////
});
if($('.auto_complete').val()==''){
$(".list_name p").hide().remove()
}
$('body').click(function(){
$(".list_name p").hide().remove();
$('.auto_complete').val('');
});
},
"error": function (x, y, z) {
// callback to run if an error occurs
alert("An error has occured:\n" + x + "\n" + y + "\n" + z);
}
});

});

php:(我使用codeigniter)

function search_hotel(){
$search_term = $this->input->post('search_hotel');
$query = $this->db->order_by("id", "desc")->like('name', $search_term)->get('hotel_submits');
$data = array();
foreach ($query->result() as $row)
{
$data[] = $row->name;
}
echo json_encode(array('name' => $data));
// echo: {"name":["333333","\u0633\u0644","\u0633\u0644\u0627\u0633\u06cc","\u0633\u0644\u0627\u0633\u0633","\u0633\u0644\u0627\u0645"]}
}

最佳答案

关于php - 为什么点击标签<a>后,页面刷新并且appendTo不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6709347/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com