一个Html页面给另一个html页面传值(或B.html页面调用A.html的参数)

版权声明:TC太子 https://blog.csdn.net/sinat_37812248/article/details/82118652

自己项目中需要用到,很多同学已经解决了这个问题,有好几种方法,但是我急用,就用了window.open方法先总结一个自己立马上手的方法,等周末或中间有空把其他方法也总结一下,主要希望自己以后再用到的时候万一忘了能快速回忆起来,也希望能帮助一下需要的同学.

A.html

                <input type="text" name="username" class="username" />
		<input type="text" name="username" class="username" />
		<input type="text" id="n" name="n"/>
		<button type="submit" id="open">打开新的页面</button>
		<script>
			u = [];
			$('#open').click(function() {
				var un = document.getElementsByName("username");
				var len = un.length;
				alert(len)
				for(i = 0; i < len; i++) {
					var ne = un[i].value;
					u.push(ne);
				}
				document.getElementById("n").value = u; 
				var ss = $('#n').val();
				alert(ss);  
				window.open('Intercept.html') //B.html 前面的是不重要,关键的是这句 
			})
		</script>

B.html

<script>
        //用window.opener. 
	var content = window.opener.document.getElementById("n").value;
	alert(content);
</script>
 
 
G
M
T
 
 
Detect languageAfrikaansAlbanianAmharicArabicArmenianAzerbaijaniBasqueBelarusianBengaliBosnianBulgarianCatalanCebuanoChichewaChinese (Simplified)Chinese (Traditional)CorsicanCroatianCzechDanishDutchEnglishEsperantoEstonianFilipinoFinnishFrenchFrisianGalicianGeorgianGermanGreekGujaratiHaitian CreoleHausaHawaiianHebrewHindiHmongHungarianIcelandicIgboIndonesianIrishItalianJapaneseJavaneseKannadaKazakhKhmerKoreanKurdishKyrgyzLaoLatinLatvianLithuanianLuxembourgishMacedonianMalagasyMalayMalayalamMalteseMaoriMarathiMongolianMyanmar (Burmese)NepaliNorwegianPashtoPersianPolishPortuguesePunjabiRomanianRussianSamoanScots GaelicSerbianSesothoShonaSindhiSinhalaSlovakSlovenianSomaliSpanishSundaneseSwahiliSwedishTajikTamilTeluguThaiTurkishUkrainianUrduUzbekVietnameseWelshXhosaYiddishYorubaZulu
 
AfrikaansAlbanianAmharicArabicArmenianAzerbaijaniBasqueBelarusianBengaliBosnianBulgarianCatalanCebuanoChichewaChinese (Simplified)Chinese (Traditional)CorsicanCroatianCzechDanishDutchEnglishEsperantoEstonianFilipinoFinnishFrenchFrisianGalicianGeorgianGermanGreekGujaratiHaitian CreoleHausaHawaiianHebrewHindiHmongHungarianIcelandicIgboIndonesianIrishItalianJapaneseJavaneseKannadaKazakhKhmerKoreanKurdishKyrgyzLaoLatinLatvianLithuanianLuxembourgishMacedonianMalagasyMalayMalayalamMalteseMaoriMarathiMongolianMyanmar (Burmese)NepaliNorwegianPashtoPersianPolishPortuguesePunjabiRomanianRussianSamoanScots GaelicSerbianSesothoShonaSindhiSinhalaSlovakSlovenianSomaliSpanishSundaneseSwahiliSwedishTajikTamilTeluguThaiTurkishUkrainianUrduUzbekVietnameseWelshXhosaYiddishYorubaZulu
 
 
 
 
 
 
 
 
 
Text-to-speech function is limited to 200 characters
 
 
Options : History : Feedback : Donate Close

猜你喜欢

转载自blog.csdn.net/sinat_37812248/article/details/82118652