简体   繁体   English

基本的HTML / Javascript-创建图像导航器-如何动态加载图像?

[英]Basic HTML/Javascript - Creating an Image Navigator - How to dynamically load images?

I am buidling a small image navigator where the user inserts an image number and it has to load in the page so he can view it and do some processing on it later. 我在构建一个小型图像导航器,用户在其中插入图像编号,并且必须将其加载到页面中,以便他可以查看该图像并在以后对其进行一些处理。

The images will be physically named 1,2,3,4,5.jpg for example. 例如,图像的物理名称为1,2,3,4,5.jpg。

Any quick code that i can use to make the corresponding image load 我可以用来加载相应图像的任何快速代码

I know this is fairly simple - but i am pretty tight on deadline and would appreciate some code that works 我知道这很简单-但我在截止日期前很紧张,希望能使用一些有效的代码

thanks a lot in advance 提前非常感谢

OK, use jquery. OK,使用jquery。 It is easy 这很容易

Here is an example 这是一个例子

HTML HTML

<input type="text" id="imagenum" />
<a href="#" class="viewimage">View Image</a>
<img class="previewimage" src="">

The Script 剧本

$(document).ready(function() {

       $(".viewimage").click(function() {
          $(".previewimage").attr('src', "imagetopath\"+$("#imagenum").val()+".jpg");
       });

       //To catch the enter key
       $('#imagenum').keypress(function(event) {
          if (event.keyCode == '13') {
               $(".previewimage").attr('src', "imagetopath\"+$(this).val()+".jpg");
          }
       });

});
<img src="<?php print $ImgValue; ?>">

seems to work as an alternative to JQuery. 似乎可以替代JQuery。

any other solution ? 还有其他解决方案吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM