0

如果变量为真,我会打开一个弹出窗口。我使用了这个脚本,但不起作用

echo "<script type=\"text/javascript\">
function doStuffRegister() {
    $( "#popupBasic2" ).popup( 'open');     
}
 </script>";
 // ... my code ...

if(!$_SESSION[page][admin])  { 
    echo "<a href=\"#popupBasic2\" data-rel=\"popup\" data-role=\"button\">click and Open popup</a>";  // this runs
} else {
echo("<script>doStuffRegister();</script>");  // this not runs
}

 //... my code .... 

echo "<div data-role=\"popup\" id=\"popupBasic2\" class=\"formpopup\" >"
."<a href=\"#home\" data-rel=\"back\" data-role=\"button\" data-theme=\"a\" data-icon=\"delete\" data-iconpos=\"notext\" class=\"ui-btn-right\">Close</a>"
  //  ."... my html code ..."
    ."</div>";

有小费吗?

4

2 回答 2

0

您可能想在 DOM 加载后尝试调用该函数。您在创建元素之前调用该函数....根据我在上面看到的内容。

希望有帮助。

干杯!

于 2013-01-08T15:37:26.890 回答
0
 if($showpopup) {

echo "<script>"
."$( document ).on( \"pageinit\", function() {"
    ."$( \".popupBrand\" ).on({  "
    ."popupbeforeposition: function() {"
    ."var maxHeight = $( window ).height() - 60 + \"px\";"
    ."$( \".popupbrand img\" ).css( \"max-height\", maxHeight );"
    ."}"
    ."});"
."});"
."</script>";

echo "<div data-role=\"popup\" id=\"popupBrand\" data-overlay-theme=\"a\" data-theme=\"d\" data-corners=\"false\">"
    // ."<a href=\"#\" data-rel=\"back\" data-role=\"button\" data-theme=\"a\" data-icon=\"delete\" data-iconpos=\"notext\" class=\"ui-btn-right\">Close</a>"
."<img class=\"popupbrand\" src=\"$filebrand\" style=\"max-height:512px;\" alt=\"\">"
."</div>";


echo "<script>"
." $(document).on(\"pageshow\", function() {"
." setTimeout(function () {"
    ."$('#popupBrand').popup('open');"
."}, 10); "// delay above zero
."});"
."$(document).on(\"click\", function() {"
."$('#popupBrand').popup('close');" 
."});  "
    ."</script> ";
  }

运行良好,我可以在任何地方单击关闭弹出窗口。

于 2013-08-20T15:11:39.423 回答