javascript - 从另一个带有返回值的html页面关闭DIV

标签 javascript php jquery html

我有一个带有文本框的 php 网页。在文本框旁边我提供了一个链接。单击链接 DIV 将打开其中包含 iram 的链接。 I 框架填充了带有 id 和描述的项目列表。现在,当我单击特定项目时,我希望 DIV 关闭并将该特定项目的 ID 提取到文本框中。

Page1.php

<html>
<body>


<input id="productid" type="text" name="productID" />
        <img src=search.gif border=1 onclick="document.all.floatDiv.style.display='inline'" alt="Expand">
        <img src=nosearch.gif onclick="document.all.floatDiv.style.display='none'" alt="Compress">

        <div id="floatDiv">
            <iframe name="moreIframe" id="moreIframe" width="99%" height="97%" align="center" src="Page2.php" style="background-color: white;"></iframe>
            <?php
            ?>
        </div>

</body>
</html>

Page2.php

<html>
<body>

<table>
    <tr>
        <td>ID</td>
        <td>Product</td>
    </tr>

    <tr>
        <td><a href="" onclick="retvalue('12')" >12</a></td>
        <td>Brass 13 mm Rod</td>
    </tr>
    <tr>
        <td><a href="" onclick="retvalue('15')" >15</a></td>
        <td>Steel 13 mm Rod</td>
    </tr>
<table>

</body>
</html>

最佳答案

将Page2.php文件的内容替换为以下内容

<table>
    <tr>
        <td>ID</td>
        <td>Product</td>
    </tr>

    <tr>
        <td><a class='test' href="" >12</a></td>
        <td>Brass 13 mm Rod</td>
    </tr>
    <tr>
        <td><a href="" class='test' >15</a></td>
        <td>Steel 13 mm Rod</td>
    </tr>
<table>
<script>
var classname = document.getElementsByClassName("test");

 for(var i=0;i<classname.length;i++){

        classname[i].addEventListener("click", function(event){
    event.preventDefault();
      var attribute = this.innerText;
      alert(attribute);
      window.parent.document.getElementById('productid').value = attribute;
});
}

</script>

关于javascript - 从另一个带有返回值的html页面关闭DIV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34101887/

相关文章:

javascript - 如果用户拒绝在 onbeforeunload 事件中离开页面,之后是否会触发一个事件?

javascript - Ember.js/Rails 嵌套 JSON

javascript - 在 onclick 事件中播放音频文件

javascript - 计算子 div 顶部位置 - 为什么需要减去父 offsetHeight?

php - 上传缺少文件扩展名

php - 为什么 opcache 没有被刷新?

javascript - 如何使 tableRow 可点击?我在网上看过但是没用

javascript - 无法在 jquery 上使用上一项和下一项链接

php - 无需 cron 在后台发送邮件

javascript - 使用 html 选择选项分配 javascript 变量