我将此代码作为搜索结果回显,但是点击事件不起作用,是否有任何建议?
<script>function BiologyFunction(){ $("#Biology").click(function(){ $("#squbomain").animate({ height:'242px'}); $("#minus").hide(); $("#menu").hide(); $("#keywords").hide(); $("#home").animate({ left:'178px', top:'71px' }); $("#search").animate({ left:'120px', top:'119px' }); $("#search").show(); $("#plus").show(); $('#searchterm').val('Biology').keyup(); }</script>
<div id="Biology" style='margin: 1px; width: 242px; height: 242px; float: left; background-image: url("squbo/content/images/biologysqubo.png"); background-size: cover;' onclick="BiologyFunction()">
<div style="left: 0px; top: 162px; width: 242px; height: 80px; position: relative; z-index: 3; background-color: rgb(45, 79, 1);">
<div style="left: 20px; top: 20px; width: 202px; height: 40px; line-height: 75%; position: absolute;">
<div style="font-size: 15px; display: inline;">
Biology
</div>
<div style="font-size: 12px; display: inline;">
is the scientific study of Life including its structure, function and evolution
</div>
</div>
</div>
</div>
以下是循环中搜索结果中生成的代码:
elseif ( $result['template'] =="4info" )
{
echo "
<script>function {$result['title']}Function(){ $(\"#{$result['title']}\").click(function(){ $(\"#squbomain\").animate({ height:'242px'}); $(\"#minus\").hide(); $(\"#menu\").hide(); $(\"#keywords\").hide(); $(\"#home\").animate({ left:'178px', top:'71px' }); $(\"#search\").animate({ left:'120px', top:'119px' }); $(\"#search\").show(); $(\"#plus\").show(); $('#searchterm').val('{$result['title']}').keyup(); }</script>
<div id=\"{$result['title']}\" onclick =\"{$result['title']}Function()\" style=\"width:242px; height:242px; float:left; margin:1px; background-image:url('squbo/content/images/{$result['image']}'); background-size:cover;\" >
<div style=\"width:242px; height:80px; position:relative; left:0px; top:162px; z-index:3; background-color:#{$result['color']};\">
<div style=\"width:202px; height:40px; position:absolute; left:20px; top:20px; line-height:75%;\">
<div style=\"display:inline; font-size:15px;\">
{$result['title']}
</div>
<div style=\"display:inline; font-size:12px;\">
{$result['description']}
</div>
</div>
</div>
</div>
";
}
要查看当前代码,请转到此处搜索生物学: http://squbo.com/mon07apr.php
答案 0 :(得分:0)
更改
<script>function {$result['title']}Function(){ $(\"#{$result['title']}\").click(function(){ $(\"#squbomain\").animate({ height:'242px'}); $(\"#minus\").hide(); $(\"#menu\").hide(); $(\"#keywords\").hide(); $(\"#home\").animate({ left:'178px', top:'71px' }); $(\"#search\").animate({ left:'120px', top:'119px' }); $(\"#search\").show(); $(\"#plus\").show(); $('#searchterm').val('{$result['title']}').keyup(); }</script>
要
<script>function {$result['title']}Function(){ $(\"#{$result['title']}\").click(function(){ $(\"#squbomain\").animate({ height:'242px'}); $(\"#minus\").hide(); $(\"#menu\").hide(); $(\"#keywords\").hide(); $(\"#home\").animate({ left:'178px', top:'71px' }); $(\"#search\").animate({ left:'120px', top:'119px' }); $(\"#search\").show(); $(\"#plus\").show(); $('#searchterm').val('{$result['title']}').keyup(); });}</script>
您错过了); }
请参阅此fiddle: