我有一个带有文本框的 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/