Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/427.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 困在js脚本中_Javascript_Php_Html - Fatal编程技术网

Javascript 困在js脚本中

Javascript 困在js脚本中,javascript,php,html,Javascript,Php,Html,我用鼠标盖有问题。 我正在研究html、php和js。 实际上,我正在制作一个页面,我想在其中更改图像的来源。 但问题是我正在从数据库中提取我的值,然后调用一个函数来用提取的数据更改src。 但它根本不起作用。如果你能遇到错误,请告诉我。 我用的是缩略图 这是我的html代码 <form id='purchase' name='info' action='index.php' method='post'> <input type='hidden' name='imagelink

我用鼠标盖有问题。 我正在研究html、php和js。 实际上,我正在制作一个页面,我想在其中更改图像的来源。 但问题是我正在从数据库中提取我的值,然后调用一个函数来用提取的数据更改src。 但它根本不起作用。如果你能遇到错误,请告诉我。 我用的是缩略图

这是我的html代码

<form id='purchase' name='info' action='index.php' method='post'>
<input type='hidden' name='imagelink' value='".$row1['images']."'/>
</form>

    <img name='unique' src='".$row1['images']."1.jpg'/>

<a href='#' id='1'><img src='".$row1['images']."thumbs/1.jpg' /></a>
<a href='#' id='2'><img src='".$row1['images']."thumbs/2.jpg' /></a>
<a href='#' id='3'><img src='".$row1['images']."thumbs/3.jpg' /></a>
<a href='#' id='4'><img src='".$row1['images']."thumbs/4.jpg' /></a>
<a href='#' id='5'><img src='".$row1['images']."thumbs/5.jpg' /></a> 

$row1['images']是保存在我的数据库中的我的图像的部分路径。

窗口中。onload
函数中,行:

var image = document.info.imagelink;
不会给出imagelink值,您需要通过将行更改为以下值来获取该值:

var image = document.info.imagelink.value;

窗口.onload
函数中,行:

var image = document.info.imagelink;
不会给出imagelink值,您需要通过将行更改为以下值来获取该值:

var image = document.info.imagelink.value;

你不能使用jQuery吗?您可以通过以下方式实现效果:

$(".thmb").click(function() {
    $("#unique").attr("src", $(this).attr("src"));
});
<img name='unique' id="unique" src='".$row1['images']."1.jpg'/>

<a href='#' class='thmb' id='1'><img src='".$row1['images']."thumbs/1.jpg' /></a>
<a href='#' class='thmb' id='2'><img src='".$row1['images']."thumbs/2.jpg' /></a>
<a href='#' class='thmb' id='3'><img src='".$row1['images']."thumbs/3.jpg' /></a>
<a href='#' class='thmb' id='4'><img src='".$row1['images']."thumbs/4.jpg' /></a>
<a href='#' class='thmb' id='5'><img src='".$row1['images']."thumbs/5.jpg' /></a> 
在HTML中,将其如下所示:

$(".thmb").click(function() {
    $("#unique").attr("src", $(this).attr("src"));
});
<img name='unique' id="unique" src='".$row1['images']."1.jpg'/>

<a href='#' class='thmb' id='1'><img src='".$row1['images']."thumbs/1.jpg' /></a>
<a href='#' class='thmb' id='2'><img src='".$row1['images']."thumbs/2.jpg' /></a>
<a href='#' class='thmb' id='3'><img src='".$row1['images']."thumbs/3.jpg' /></a>
<a href='#' class='thmb' id='4'><img src='".$row1['images']."thumbs/4.jpg' /></a>
<a href='#' class='thmb' id='5'><img src='".$row1['images']."thumbs/5.jpg' /></a> 

您不能使用jQuery吗?您可以通过以下方式实现效果:

$(".thmb").click(function() {
    $("#unique").attr("src", $(this).attr("src"));
});
<img name='unique' id="unique" src='".$row1['images']."1.jpg'/>

<a href='#' class='thmb' id='1'><img src='".$row1['images']."thumbs/1.jpg' /></a>
<a href='#' class='thmb' id='2'><img src='".$row1['images']."thumbs/2.jpg' /></a>
<a href='#' class='thmb' id='3'><img src='".$row1['images']."thumbs/3.jpg' /></a>
<a href='#' class='thmb' id='4'><img src='".$row1['images']."thumbs/4.jpg' /></a>
<a href='#' class='thmb' id='5'><img src='".$row1['images']."thumbs/5.jpg' /></a> 
在HTML中,将其如下所示:

$(".thmb").click(function() {
    $("#unique").attr("src", $(this).attr("src"));
});
<img name='unique' id="unique" src='".$row1['images']."1.jpg'/>

<a href='#' class='thmb' id='1'><img src='".$row1['images']."thumbs/1.jpg' /></a>
<a href='#' class='thmb' id='2'><img src='".$row1['images']."thumbs/2.jpg' /></a>
<a href='#' class='thmb' id='3'><img src='".$row1['images']."thumbs/3.jpg' /></a>
<a href='#' class='thmb' id='4'><img src='".$row1['images']."thumbs/4.jpg' /></a>
<a href='#' class='thmb' id='5'><img src='".$row1['images']."thumbs/5.jpg' /></a> 


Post-rendered HTML,这里不需要PHP。您是否验证了图像的路径有效?一些浏览器会向您显示一个损坏的图像图标,其他浏览器则会隐藏图像而不向您显示任何内容。(这让我发疯)一件简单的事情是尝试将生成的图像URL粘贴到地址栏中,并验证路径是否正确。如果你只差一个字符,它就会断开。(我已经这样做了,以前也错过了斜杠之类的东西)后渲染HTML,这里不需要PHP。你验证过图像的路径了吗?一些浏览器会向您显示一个损坏的图像图标,其他浏览器则会隐藏图像而不向您显示任何内容。(这让我发疯)一件简单的事情是尝试将生成的图像URL粘贴到地址栏中,并验证路径是否正确。如果你只差一个字符,它就会断开。(我做过这件事,以前也错过过类似斜杠的事情)