dongying3830 2012-12-29 05: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-29 05: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 (=).

    评论

报告相同问题?