摘要:
此代码位于包含在html文件中的外部javascipt文件中,当<a href='#' class='btn btn-"+idinc+"' id='opener' onclick='sendJson('"+str+"')'>Book</a>
被点击的函数调用正确并且发生错误时,我遇到错误。
脚本:
$(document).ready(function(e) {
var url = "http://localhost/json/ticket.json";
$("#search-btn").click(function() {
$.getJSON(url, function(obj) {
var idinc = 1;
var str = "";
$.each(obj, function(key, value) {
//$('#result-input .flight_no').val()=value.status;
var status = value.status;
$("#search_result").append(
"<div class='row' id='result-input-"+idinc+"'>
<div class='flight_no'><p id='flight-no-"+idinc+"'>"+value.flightNo+"</p></div>
<div class='flight_date'> <p id='departure-time-"+idinc+"'>Deptr: "+value.departureTime+"</p><p id='arrival-time-"+idinc+"'>arrival: "+value.arrivalTime+"</p></div><div class='flight_date'><p id='from-"+idinc+"'>From: "+value.fromAirport+"</p><p id='to-"+idinc+"'>To: "+value.toAirport+"</p></div>
<div class='flight_book'><a href='#' class='btn btn-"+idinc+"' id='opener' onclick='sendJson('"+str+"')'>Book</a></div>
</div>");
idinc=idinc+1;
});
});
});
});
将在点击时调用的函数。此函数位于html文件中:
<script>
function sendJson(mystr) {
alert(mystr);
}
</script>