javascript不同頁面?zhèn)髦档母倪M(jìn)版
更新時(shí)間:2008年09月30日 00:06:47 作者:
改進(jìn)點(diǎn):支持同頁面有多個(gè)文本框,可自動(dòng)向不同的文本框傳值。先看演示吧
其實(shí)原理也很簡單。同樣先通過getAttribute判斷type屬性,捕捉到按鈕。然后在按鈕onclick時(shí)把i通過url傳入子頁面。
<h2>input1</h2>
<input type="text" /><input type="submit" />
<h2>input2</h2>
<input type="text" /><input type="submit" />
<script type="text/javascript"><!--
var aInput = document.getElementsByTagName("input");
for (i = 0 ; i < aInput.length ; i++ )
{
(
function (i){
if (aInput[i].getAttribute("type") == "submit")
{
aInput[i].onclick = function (){
window.open('b.html?'+i,'newwindow','height=100,width=400')
}
}
}
)(i)
}
// --></script>
子頁面用slice方法對(duì)url進(jìn)行切分。并使用window.opener方法捕捉到父頁面的文本框,進(jìn)行賦值。 一切就OK了
<h2>openWindow</h2>
<input type="text" /><input type="submit" />
<script type="text/javascript"><!--
var aInput = document.getElementsByTagName("input");
for (i = 0 ; i < aInput.length ; i++ )
{
if (aInput[i].getAttribute("type") == "text") var textboxB = new Object(aInput[i]);
if (aInput[i].getAttribute("type") == "submit") var btnB = new Object(aInput[i]);
}
btnB.onclick = function(){
var sTextValue = textboxB.value
var aInput = window.opener.document.getElementsByTagName("input");
var sUrl = document.location;
var sNo = sUrl.toString().slice(-1)
window.opener.aInput[sNo-"1"].value = sTextValue
window.close();
}
// --></script>
復(fù)制代碼 代碼如下:
<h2>input1</h2>
<input type="text" /><input type="submit" />
<h2>input2</h2>
<input type="text" /><input type="submit" />
<script type="text/javascript"><!--
var aInput = document.getElementsByTagName("input");
for (i = 0 ; i < aInput.length ; i++ )
{
(
function (i){
if (aInput[i].getAttribute("type") == "submit")
{
aInput[i].onclick = function (){
window.open('b.html?'+i,'newwindow','height=100,width=400')
}
}
}
)(i)
}
// --></script>
子頁面用slice方法對(duì)url進(jìn)行切分。并使用window.opener方法捕捉到父頁面的文本框,進(jìn)行賦值。 一切就OK了
復(fù)制代碼 代碼如下:
<h2>openWindow</h2>
<input type="text" /><input type="submit" />
<script type="text/javascript"><!--
var aInput = document.getElementsByTagName("input");
for (i = 0 ; i < aInput.length ; i++ )
{
if (aInput[i].getAttribute("type") == "text") var textboxB = new Object(aInput[i]);
if (aInput[i].getAttribute("type") == "submit") var btnB = new Object(aInput[i]);
}
btnB.onclick = function(){
var sTextValue = textboxB.value
var aInput = window.opener.document.getElementsByTagName("input");
var sUrl = document.location;
var sNo = sUrl.toString().slice(-1)
window.opener.aInput[sNo-"1"].value = sTextValue
window.close();
}
// --></script>
相關(guān)文章
JavaScript 實(shí)現(xiàn)拖拽效果組件功能(兼容移動(dòng)端)
這篇文章主要介紹了JavaScript 實(shí)現(xiàn)拖拽效果組件功能(兼容移動(dòng)端),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-11-11淺談JavaScript對(duì)象的創(chuàng)建方式
下面小編就為大家?guī)硪黄獪\談JavaScript對(duì)象的創(chuàng)建方式。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考,一起跟隨小編過來看看吧2016-06-06JS中call apply bind函數(shù)手寫實(shí)現(xiàn)demo
這篇文章主要為大家介紹了JS中call apply bind函數(shù)手寫實(shí)現(xiàn)demo,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03微信小程序?qū)崿F(xiàn)電子簽名并導(dǎo)出圖片
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)電子簽名,并導(dǎo)出圖片,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-05-05JS+CSS實(shí)現(xiàn)滾動(dòng)數(shù)字時(shí)鐘效果
本篇文章教給大家用JS代碼配合CSS樣式來實(shí)現(xiàn)滾動(dòng)時(shí)鐘的動(dòng)畫效果,一起來學(xué)習(xí)下。2017-12-12JavaScript、jQuery與Ajax的關(guān)系
這篇文章主要介紹了 JavaScript、jQuery與Ajax的關(guān)系的相關(guān)資料,需要的朋友可以參考下2016-01-01