Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/392.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 使用jQuery和LocalStorage永久启用按钮并更改其映像src_Javascript_Jquery_Html_Local Storage - Fatal编程技术网

Javascript 使用jQuery和LocalStorage永久启用按钮并更改其映像src

Javascript 使用jQuery和LocalStorage永久启用按钮并更改其映像src,javascript,jquery,html,local-storage,Javascript,Jquery,Html,Local Storage,我有一个已禁用的按钮,我想通过单击另一个按钮来启用该按钮,并将其永久启用。该按钮有一个图像,在该按钮启用的同时,图像src应该更改。这是我的代码: <!--This is the button that enables the img_tema2 button--> <a id="a_tema1" href="principal.html" class="btn btn-success">Enviar</a> <!--This is the img_t

我有一个
已禁用的
按钮,我想通过单击另一个按钮来启用该按钮,并将其永久启用。该按钮有一个图像,在该按钮启用的同时,图像
src
应该更改。这是我的代码:

<!--This is the button that enables the img_tema2 button-->
<a id="a_tema1" href="principal.html" class="btn btn-success">Enviar</a>

<!--This is the img_tema2 button-->
<div class="col-lg-4">
    <button class="tsbutton" onclick="window.location='tema_2.html';" id="img_tema2">
        Tema 2
        <img id="gif_tema2" class="img-circle2" src="../assets/img/segundo_tema_gris.gif" alt="Generic placeholder image" width="140" height="140">
    </button>
</div>
对不起,我完全忘了解释很多事情

a_tema1
位于不同的HTML上。 当我打开html时,按钮
img_tema2
没有被禁用,正如我前面所说,我需要首先禁用它,当我单击
a_tema1
时,它被启用。 添加行
$(“#img_tema2 img”).attr(“src”,“”)这是推荐的,它也不做任何事情。
我可能做错了什么


对不起,我的英语不好。谢谢你给我的帮助。我不知道你到底想做什么,但这是我的解释:

HTML:


我不确定你到底想做什么,但这是我的解释:

HTML:


图像src应该更改为什么?您的代码现在不起作用了吗?为什么要在
$(“#img_tema2”).prop(“disabled”,false)上分配
href
;在此之后添加$(“#img_tema2 img”).attr(“src”,“new img src”);如果要在按钮启用时更改图像,则图像src应更改为什么?您的代码现在不起作用了吗?为什么要在
$(“#img_tema2”).prop(“disabled”,false)上分配
href
;在此之后添加$(“#img_tema2 img”).attr(“src”,“new img src”);如果你想在按钮启用时更改图像。这正是我需要的,非常感谢,你真的救了我的命。这正是我需要的,非常感谢,你真的救了我的命
<!--This is the button that enables the img_tema2 button-->
<div id="a_tema1" class="btn btn-success">Enviar</div>
<br/><br/>
<!--This is the img_tema2 button-->
<div class="col-lg-4">
  <button class="btn" onclick="window.location='tema_2.html';" id="img_tema2">
    Tema 2
    <img id="gif_tema2" class="img-circle2" src="https://i.imgur.com/fBE8b1k.png" alt="Generic placeholder image" width="140" height="140">
  </button>
</div>

<br/><br/><br/><br/>
<p>Icons made by <a href="http://www.flaticon.com/authors/freepik" title="Freepik">Freepik</a> from <a href="http://www.flaticon.com" title="Flaticon">www.flaticon.com</a> is licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0"
  target="_blank">CC 3.0 BY</a></p>
$("#img_tema2").attr("disabled", "disabled");

$(function() {
    var showLittleHeader = localStorage.getItem('#img_tema2');
    if (showLittleHeader) {
      $("#img_tema2").removeAttr("disabled");
      $("#gif_tema2").attr("src", "http://i.imgur.com/fNerL36.png");
    }

  $('#a_tema1').on('click', function() {
    localStorage.setItem("#img_tema2", 1);
    $("#gif_tema2").attr("src", "http://i.imgur.com/fNerL36.png");
    $("#img_tema2").removeAttr("disabled");
  });
});