我打算使用jquery函数插入到另一个PHP页面的链接,但是代码不起作用...也尝试了attr()之类的替代方法,但结果仍然相同。有人可以给我有关此事的建议吗?以下是我的代码:
$(document).ready(
function(){
$('#date').change(
function(){
$.ajax (
{
url: 'process.php',
type: 'post',
data: {
item_no:2,
movie_id: $('#movie').val(),
movie_date: $('#date').val()
},
dataType: 'json',
success: function(response){
$('#showtime').empty();
for(var i = 0; i<response.length; i++){
var showtime = response[i]['showtime'];
$('#showtime').append("<a href='movie_seat.php?id="+showtime+"' id='seatlink'>");
$('#showtime').append("<font style='margin-right:50px;'>");
$('#showtime').append(showtime);
$('#showtime').append("</font></a>");
} // for loop
} // function taking response
} // block in ajax
); //ajax
} // function inside change
); // select->date change
} // function inside ready
); // document.ready
** #showtime是属性的ID
我的期望:显示的值应该能够作为将用户定向到另一个php页面的链接。但是显然,它不是....
您需要将所有内容一起添加,因为如果您添加以下内容:
$('#showtime').append("<a href='movie_seat.php?id="+showtime+"' id='seatlink'>");
$('#showtime').append("<font style='margin-right:50px;'>");
$('#showtime').append(showtime);
$('#showtime').append("</font></a>");
这样,标签将被关闭,并且您的html看起来像这样:
<a href="movie_seat.php?id={idshowtime}" id="seatlink"></a>
<font style="margin-right:50px;"></font>
showtime
所以您需要做的是将所有内容附加在一起,我的意思是标签内的标签,请尝试以下操作:
var link = "<a href='movie_seat.php?id="+showtime+"' id='seatlink'>"
+ "<font style='margin-right:50px;'>"
+ showtime
+ "</font></a>";
$('#showtime').append(link);