Home >Backend Development >PHP Tutorial >请教页面上多个点击事件调用一个jq函数的问题

请教页面上多个点击事件调用一个jq函数的问题

WBOY
WBOYOriginal
2016-06-20 12:31:581197browse

页面上要实现生成多个【点击阅读】的弹出层,弹出层用的是layer插件,然后我在php文件中写了一个根据用户数与用户名称自动生成jq代码段的函数 如下:
function setLayerScript($i,$girlName)
{
    $scriptText = "
        <script> <br /> $(document).ready(function() { <br /> $('#layer{$i}').click(function() { <br /> layer.open({ <br /> type: 2, <br /> title: {$girlName}+'の心情日记', <br /> shadeClose: true, <br /> shade: 0.8, <br /> area: ['85%', '90%'], <br /> content: 'indexMoudle/diaryPage.html' <br /> }); <br /> }); <br /> }); <br /> </script>
        ";
    return $scriptText;
}
当写到html中以后 a标签通过id无法调用该函数执行 请问大大该如何解决?谢谢了!


回复讨论(解决方案)

$('#layer{$i}').click(function() {
  layer.open({
    type: 2,
    title: {$girlName}+'の心情日记',
    shadeClose: true,
    shade: 0.8,
    area: ['85%', '90%'],
    content: 'indexMoudle/diaryPage.html'
  });
   return false;
});

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn