Jquery method to get the value of the tag under the body in the same origin iframe

  • 2020-03-30 04:01:43
  • OfStack

Test. The HTML

The Html code


<!DOCTYPE HTML> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>jquery</title> 
<style type="text/css"> 
</style> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> 
<script type="text/javascript"> 
$(document).ready(function (){ 
$("#show").click(function (){ 
var iframeObj = $(window.frames["iframe_name"].document); 
alert(iframeObj.find("#un").val()); 

}); 

}); 
</script> 
</head> 
<body> 
<input type="button" id="show" value="show" /> 
<iframe id="iframe_id" name="iframe_name" src="http://localhost/test/login.html"></iframe> 
</body> 
</html>

The login. The HTML

The Html code


<!DOCTYPE html> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<title> The login page </title> 
</head> 
<body> 
<form method="POST" action="#"> 
 User name: <input id="un" type="text" name="username" value="123d" /> 
 The secret   Code: <input type="text" name="password"/> 
<input type="submit" value=" submit "> 
</form> 
</body> 
</html>

Related articles: