简体   繁体   中英

How to insert variables in quotes inside quotes in JavaScript

I am writing a javascript in pug.

I am using express and mongodb to create a crud, and I want to generate an edit button for each post and generate an event.

The result I want is "edit_form_1" but "edit_form_4 {post._id}" is returned.

What mistakes have I made?

I wrote the following code:

index.pug

...
head
      script.
      function click(id) => {
        let element = document.getElementById(id);
        if element.display == 'none' {
          element.display = 'block'
        }
        else {
          element.display = 'none'
        }
      }
...
body
      a(onclick=`click(`div_${post._id}`)`) 수정
      div(id=`div_${post._id}` style="display: none;)

I think that you may have too many backticks in your first line, try this:

a(onclick=`click(div_${post._id})`) 수정
div(id=`div_${post._id}` style="display: none;")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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