Jquery弹出不正确的工作在PHP foreach
jquery popup not correct work in php foreach
我正在使用这个jquery弹出窗口
$(document).ready(function() {
// Here we will write a function when link click under class popup
$('a.popup').click(function() {
// Here we will describe a variable popupid which gets the
// rel attribute from the clicked link
var popupid = $(this).attr('rel');
// Now we need to popup the marked which belongs to the rel attribute
// Suppose the rel attribute of click link is popuprel then here in below code
// #popuprel will fadein
$('#' + popupid).fadeIn();
// append div with id fade into the bottom of body tag
// and we allready styled it in our step 2 : CSS
$('body').append('<div id="fade"></div>');
$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
// Now here we need to have our popup box in center of
// webpage when its fadein. so we add 10px to height and width
var popuptopmargin = ($('#' + popupid).height() + 10) / 2;
var popupleftmargin = ($('#' + popupid).width() + 10) / 2;
// Then using .css function style our popup box for center allignment
$('#' + popupid).css({
'margin-top' : -popuptopmargin,
'margin-left' : -popupleftmargin
});
});
// Now define one more function which is used to fadeout the
// fade layer and popup window as soon as we click on fade layer
$('#fade').click(function() {
// Add markup ids of all custom popup box here
$('#fade , #popuprel , #popuprel2 , #popuprel3').fadeOut()
return false;
});
});
这是我foreach循环中的PHP和HTML代码
<?php foreach($items as $item){ ?>
<a rel="popuprel" class="popup">click hier</a>
<div class="popupbox" id="popuprel">
<div id="intabdiv">
<?php echo $item->description; ?>
</div>
</div>
<div id="fade"></div>
<?php } ?>
现在,当点击并显示弹出窗口只回声一个项目的所有项目的描述,但我想回声每个项目的每个项目的描述。
Javascript:
<script>
function show_description(id)
{
$('desc').fadeOut();
$('#description_' + id).fadeIn();
}
</script>
PHP/HTML: <?php foreach($items as $item){ ?>
<a rel="popuprel" onclick="show_description(<?=$this->id; ?>);">click hier</a>
<div class="popupbox" id="popuprel">
<div class="desc" id="description_<?=$this->id;?>">
<?php echo $item->description; ?>
</div>
</div>
<div id="fade"></div>
<?php } ?>
我假设你可以用"$this-> ID"获取你的项目的ID,这就是为什么我在代码中使用它。
我发现怎么能做到我将所有popuprel替换为以下代码:
$item->id
现在可以工作了
相关文章:
- 如何在PHP foreach中使用ajax
- Wordpress:Jquery.html函数现在在PHP foreach循环中执行
- PHP foreach 提供的参数无效
- Javascript getElementById from php foreach loop
- PHP foreach 循环和每个循环的一个 AJAX 调用
- Javascript into PHP foreach loop
- 来自 PHP foreach 循环的隐藏输入值未正确传递给 JQuery
- Dynamic Jquery Tabs based on Php foreach
- javascript loader in php foreach
- 从PHP foreach循环中获取Ajax变量(第二部分)
- 从PHP foreach循环设置不同的JS变量
- PHP foreach in JavaScript
- 结合vejs v-repeat和php foreach循环
- Jquery .text() with php foreach
- 调用php foreach的Javascript函数.这可能吗?
- 将PHP foreach插入到jquery追加函数中
- 如何获得id和类型在php foreach循环,并通过ajax发送到服务器
- 在php foreach中使用jquery动态选择器删除单个图像
- jQuery函数没有在PHP foreach循环中执行
- Jquery弹出不正确的工作在PHP foreach