且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何输入图片网址并获得图片预览

更新时间:2023-11-27 20:43:22

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>Image preview</title>
	<link rel="stylesheet" href="">

	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

	<script type="text/javascript">
		jQuery(document).ready(function($) {
			
			$('#imgName').bind('input', function() {
			    $('#imageHolder').attr('src', $(this).val()); //concatinate path if required
			});

		});
	</script>
</head>
<body>
	<input type="text" name="" id="imgName" value="" placeholder="Input image name"><br><br>
	<img name="imageHolder" id="imageHolder" src="http://i.imgur.com/zAyt4lX.jpg">
</body>
</html>