dongzan7016 2013-05-07 15:09
浏览 32
已采纳

访问未加载的php文件中的元素

I have A main page called index.php where I have a link like the below

<a href="bedview.php" target="main" onclick="javascript:showHideBedsNurse('JimAndersson')">Filter Person</a>

where main is an iframe like below.

<div id="middle" >
    <iframe id="main" src="home.html">
    </iframe>
</div>

The function called showHideBedsNurse(Name) looks like this

function showHideBedsNurse(Name){
        $('.bedclass').hide();
        alert("got Here");
}

Now to my question: it displays the alert message I.E it executes the function but the function Can't access the elements in bedview.php (So no classes called .bedclass are found and hidden). I want to state in the function to load the page bedview.php with all classes called .bedclass to be hidden and in this case show all the classes .JimAndersson I.E the parameter called Name.

Is this doable in an easy way? I'm currently stuck. The function works if I execute the function in bedview.php but not as I said if I execute it when loading the bedview.php from index.php.

And no I do not want it to load bedview.php with .bedclass hidden as default, only when clicking on this link and execute the function

Thanks in advance =)

  • 写回答

1条回答 默认 最新

  • doubinduo3364 2013-05-07 15:25
    关注

    There are several ways to do this. One would be to pass a variable to bedview.php, such as:

    <a href="bedview.php?hide=JimAndersson" target="main">Filter Person</a>
    

    Then grab the hide variable in bedview.php (that is, $_GET['hide']) and hide all elements matching its value (in this case, JimAndersson). You can do this by calling your showHideBedsNurse JavaScript function in bedview.php and passing it the value of $_GET['hide']:

    <script>
        showHideBedsNurse("<?php echo htmlspecialchars($_GET['hide']); ?>");
    </script>
    

    Keep in mind this is a very simple example just to show you the logic. Normally I wouldn't recommend mixing JS and PHP this way.

    I'm also not clear on what exactly your showHideBedsNurse function does—what's the point of passing it a name if you don't use the name in the function? You might want to rethink your approach entirely here. Look into using AJAX calls for this instead.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思