单击时td不起作用并获取值

时间:2014-12-02 15:40:25

标签: ajax get html-table

我正在构建搜索输入。当用户在该输入框中键入时,我想自动显示具有相同单词的最近对象,如用户类型。看起来像这样:

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

function hasil_cari(){
		var hasil = $("#tujuan_cepat").val();
		$.ajax({
			url: "ambildataobjek.php",
			data: "hasil="+hasil,
			cache: true,
			success: function(msg){
				$("#form_hasil_pencarian").html(msg);
				$('.form_hasil_pencarian').show();
			}
		});
	}
	
	
		
	$(document).on('click','.hasil_pencarian',function() {
     alert("this");
     document.getElementById("navigasi_cepat").disabled = false;

	});
   
<div id="pencarian">
    <form id="form_navigasi_cepat" name="form_navigasi_cepat" method="POST">
     <input type="text" class="textboxutama"  name="tujuan_cepat" id="tujuan_cepat" onKeyPress="hasil_cari();" placeholder="Alamat Yang dituju" required>
     <input type="text" class="textboxutama" id="lokasi_tersembunyi" name="lokasi_tersembunyi" hidden>
     <button type="submit" class="buttonutama" id="navigasi_cepat" disabled>Rute</button>
     <br>
     <div id="form_hasil_pencarian" class="form_hasil_pencarian" hidden>
     </div>
    </form>
    
    </div>

对于查询,我使用ajax。这是gettig objek的文件ambildataobjek.php:

<?php

if (isset($_GET['hasil'])){    
   	include ("php/connect.php");
	$hasil = $_GET['hasil'];
	$hasil_objek = mysql_query("SELECT w.nama_wisata, l.lat_lokasi, l.lang_lokasi FROM lokasi l, wisata w, jenis j WHERE (w.nama_wisata LIKE '%$hasil%' or j.nama_jenis LIKE '%$hasil%') and w.idjenis_wisata = j.id_jenis and l.id_lokasi=w.idlokasi_wisata");
	while($k = mysql_fetch_array($hasil_objek)){
?>
<table width="100%" border="1" id="tabel_hasil_pencarian">

<?PHP
		echo "<tr>";
		echo "<td class=\"hasil_pencarian\">".$k['nama_wisata']."</td>\n";
		echo "</tr>";
	}    
} 


?>

</table>

当我从显示的ajax中单击td时,我想将td值输入id =“tujuan_cepat”,但我不能。 我如何从那个td获得价值?

0 个答案:

没有答案