如果jquerymobile中的变量为true,则使用javascript打开弹出窗口

时间:2013-01-08 15:34:14

标签: php jquery-mobile popup

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

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>";

任何提示?

2 个答案:

答案 0 :(得分:0)

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

希望有所帮助。

干杯!

答案 1 :(得分: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> ";
  }

运行正常,我可以在任何地方关闭弹出窗口。