我希望在ajax的帮助下显示所选图片的幻灯片,并且这样做获取标题对于显示相应的幻灯片显示非常重要,但在 JavaScript中,点击的图片的标题不会被提取。 < / p>
的javascript:
function slide(s) {
var _event = s;
alert(_event);
}
码
<div id="inner_body">
<?php
$c = mysql_connect("localhost", "abc", "xyz");
mysql_select_db("root");
$sql = "select * from images where year=2000";
$qc = mysql_query($sql);
$count = 0;
while ($ans = mysql_fetch_array($qc)) {
$title = ucwords($ans['event']);
print "
<div class='img-wrap' onclick='slide($title)'>
<img id='display_img' src='images/thumbnails/$ans[image1]'>
<div class='img-overlay'>
<b1>" . $title . "</b1>
</div>
</div>";
}
?>
</div>
答案 0 :(得分:1)
缺少引号标记
onclick='slide($title)'; //render onclick='slide(xxxx)'
//should be
onclick='slide(\"$title\")'; //render onclick='slide("xxxx")'
图片代码<image />
或<image></image>
<b1>
未定义(<b></b>
也是过时的旧版HTML)。这应该是<strong>...</strong>
答案 1 :(得分:0)
在onclick上传递this
并使用带有类title
的jquery find子元素获取html的值。
<强>的Javascript 强>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
function slide(s)
{
alert($(s).find('.title').html());
}
</script>
<强>码强>
<div id="inner_body">
<?php
$c = mysql_connect("localhost", "abc", "xyz");
mysql_select_db("root");
$sql = "select * from images where year=2000";
$qc = mysql_query($sql);
$count = 0;
while ($ans = mysql_fetch_array($qc)) {
$title = ucwords($ans['event']);
print "
<div class='img-wrap' onclick='slide(this)'>
<img id='display_img' src='images/thumbnails/$ans[image1]'>
<div class='img-overlay'>
<b1 class='title'>" . $title . "</b1>
</div>
</div>";
}
?>
</div>