我正在使用脚本,需要制作多个事件才能使弹出窗口显示。javascript - 用于循环制作事件
我尝试这样做,但它不工作:
for (i=0;i<=storingen;i++)
{
$("#storing" + i).click(function(){ centerPopup(); loadPopup(); });
}
输出应该是:
$("#storing0").click(function(){ centerPopup(); loadPopup(); });
$("#storing1").click(function(){ centerPopup(); loadPopup(); });
$("#storing2").click(function(){ centerPopup(); loadPopup(); });
$("#storing3").click(function(){ centerPopup(); loadPopup(); });
等
不过的div id为#storing量(号码在这里)是可变的,所以我想这样做,但它不工作...
我从PHP得到storingen变量:
<script type="text/javascript">aantalstoringen('.$aantalstoringen.')</script>
我在js文件这样的回暖:
function aantalstoringen(storingen){
storingen=storingen;
}
我做了一个警报(storingen),其追溯权数,这样就可以了。
难道是for循环行不通的,因为心不是在aantalstoringen功能,但在另一个功能:
$(document).ready(function() {
我用这个教程做的JavaScript: http://yensdesign.com/2008/09/how-to-create-a-stunning-and-smooth-popup-using-jquery/#popup1 和脚本你得到的是这样的: http://yensdesign.com/tutorials/popupjquery/popup.js
我建议你给所有这些元素的同一类,只是做'$(“类名”)。点击(函数( ){...});'。 –
此外,我想指出,这个功能是[如你可以在链接的popup.js文件中看到的]显示特定的div。 每个div有不同的ID,因为内容不同,所以我不能使用该功能来搜索ID存储的每个元素* 如果我不是很清楚,我很抱歉。 – laarsk