My code is as follows
Title
test
test2
I don’t want to get the value of each P, just as an analogy. I want to know how to dynamically render the code inside
When there are three .name p
test
test2
test3
Then the final code in
How can we achieve this effect?
Do you want the return result in fun1() to be used as the execution js statement? ? You can use eval() to execute
You can directly define fun1 to return the text of the specified
className
DOM, and then just run it directly. Anyway, when you generate code, you want to execute it immediately.You don’t need to dynamically generate scripts, the script itself is very flexible. The code below is equivalent to the one you want to generate
If you want to loop through each
.name p
you can directlyIf you want to process the specified name, you can
So what you want to do must be handled by dynamically generated scripts? If it is really needed, this is usually done by the server, not the front end. If the front-end can generate a script to run, it can definitely run a certain piece of code directly...