免费人成网站视频在线观看国内,久视频精品线在线观看,人妻激情偷乱频一区二区三区,国产 字幕 制服 中文 在线

JS實(shí)現父頁(yè)面和子頁(yè)面相互傳值_網(wǎng)絡(luò )編程_奇迪科技(深圳)有限公司(m.cheanjie.com)

歡迎來(lái)到奇迪科技(深圳)有限公司,超值服務(wù)提供卓越產(chǎn)品!

網(wǎng)絡(luò )編程

JS實(shí)現父頁(yè)面和子頁(yè)面相互傳值

作者:m.cheanjie.com 來(lái)源: 更新時(shí)間:2024-01-22

制作個(gè)網(wǎng)站頁(yè)面,想實(shí)現點(diǎn)擊彈出一個(gè)頁(yè)面,把父頁(yè)面的值傳遞到子頁(yè)面,在子頁(yè)面處理完后,關(guān)閉子頁(yè)面,把值再傳回父頁(yè)面,而不刷新父頁(yè)面,通過(guò)JS實(shí)現,以下是JS實(shí)現的代碼展示:

一、父頁(yè)面/父窗口

<input type="text" id="oldPath" name="picPath" value="$info"> 
<a href="javascript:;" onclick="openWin('../upFile');">傳值到子頁(yè)面</a>
<script>
    function openWin(str) {
        document.getElementById("oldPath").value = document.getElementById("oldPath").value;   
        window.open(str, null,'width=550,height=500'); // 打開(kāi)窗口
    } 
</script>


二、子頁(yè)面/子窗口:

<div class="content">
<script language="javascript">   
//獲取父窗口的值
var prtW = window.opener;
var prtA;
if(prtW!=null){
    prtA = prtW.document.getElementById("oldPath").value;
    document.getElementById("oldUrl").value=prtA;
}
//傳值到父窗口
function getValue() {
window.opener.document.getElementById('oldPath').value = document.getElementById('picPath').value // 賦值
window.opener.document.getElementById('pic').src = document.getElementById('picPath').value // 賦值
window.close(); // 關(guān)閉窗口
}
</script>
    <input type="text" id="picPath" value="$info">
    <a href="#" onclick="getValue()" >傳值到父頁(yè)面</a>
</div>


以上代碼經(jīng)過(guò)測試,能實(shí)現預想的功能。

本文版權所有,轉載須注明:來(lái)源  http://m.cheanjie.com/qvdv-oop-123.html