dongying3830 2012-12-28 21:34
浏览 18

每次变量变化时调用函数

<script>
function myFunction(a){

    document.getElementById("demo").innerHTML=a;
}
</script>

code to change variable on click

<?php

$as=array(0,1,2,3,4,5); 
$a=sizeof($as);
echo'<div class="navbox">
<ul class="nav">';
for($i=1;$i<$a;$i++){

    echo '<li><a href="#" onclick="myFunction('.$as[$i].')">'.$as[$i].'</li>';
}

$u='<p id="demo"></p>';
echo $u;
ifrm();
function ifrm(){

    global $u;
    if($u=''){

        echo 'empty';
    }
    else{

        $y='index.php?x='.$u;
        echo '<iframe src='.$y.'></frame>';
    }
}
?>

call the function ifrm(); each time the variable $u changes but it calls only ones what should it gets called

展开全部

  • 写回答

1条回答 默认 最新

  • dousikuai5417 2012-12-28 21:56
    关注

    I assume you want something to be called every time you change the innerHTML of the demo paragraph. The function irm() is server-side, in PHP, so once the page has loaded it cannot be called by JavaScript. You'll have to write this function with the behavior you want in JavaScript, and then call it after you reset the innerHTML in myFunction().

    PS: I think you want the comparison operator (if ($u == '')) in your if statement, not the assignment operator (=).

    评论
    编辑
    预览

    报告相同问题?

    手机看
    程序员都在用的中文IT技术交流社区

    程序员都在用的中文IT技术交流社区

    专业的中文 IT 技术社区,与千万技术人共成长

    专业的中文 IT 技术社区,与千万技术人共成长

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    客服 返回
    顶部