Jump to content

js dentro de função js


Deus

Recommended Posts

Boa noite.

Outro problema que estou a ter é que agora tenho um codigo js que quero correr no meu site e esse codigo depende do estado de uma variavel.

Ou seja vou fazer switch/case e para isso tem de ser em php ou js, o meu problema é como correr depois o codigo dentro do js.

<script>
switch(vari)
{
case 1:
<script src="minha fonte">
</script>
break;
case 2:
<script src="minha fonte2">
</script>
break;
}
</script>
Edited by Deus

Linguagens: C / Java / Prolog / Assembly / HTMLA aprender: Java

Link to comment
Share on other sites

Sabes que podes fazer isso sem precisar de definir JS dentro de JS... Colocas simplesmente o código que queres correr dentro dos cases. Se for demasiado grande/complexo, crias duas funções distintas e mandas executar a função respectiva consoante o case.

“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.