javascript中的$是什么意思? [英] What does $ mean in javascript?

查看:105
本文介绍了javascript中的$是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码可以使用(有人为我写了),但其中的$包含了我。我在网上看过它是一个标识符,但在我的情况下它不能作为标识符。我用其他任何东西替换$符号,后面的函数不起作用。这是代码:



I have this code that works (someone wrote it for me), but the $ in it eludes me. I have read online it's an identifier, but it doesn't work as an identifier in my case. I replace the $ sign by anything else, the function that follows doesn't work. Here's the code:

var modal = document.getElementById('modal');

var img = document.getElementsByClassName('.image');
var modalImg = $("#modal-img");
var captionText = document.getElementById("modal-text");
$('.image').click(function(){
    modal.style.display = "block";
    var newSrc = this.src;
    modalImg.attr('src', newSrc);
    captionText.innerHTML = this.alt;
});

var span = document.getElementsByClassName("close-x")[0];

span.onclick = function() {
  modal.style.display = "none";





谢谢



我尝试了什么:



我试过用getElementById之类的东西替换$ ,任何其他标识符等。



Thanks

What I have tried:

I have tried replacing the $ by stuff like getElementById, any other identifier, etc.

推荐答案

就在我身上。我在网上看过它是一个标识符,但在我的情况下它不能作为标识符。我用其他任何东西替换
in it eludes me. I have read online it's an identifier, but it doesn't work as an identifier in my case. I replace the


符号,后面的函数不起作用。这是代码:



sign by anything else, the function that follows doesn't work. Here's the code:

var modal = document.getElementById('modal');

var img = document.getElementsByClassName('.image');
var modalImg =


#模态-IMG);
var captionText = document .getElementById( modal-text);
("#modal-img"); var captionText = document.getElementById("modal-text");


这篇关于javascript中的$是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆