开发者

is this valid javascript?

开发者 https://www.devze.com 2023-01-24 21:39 出处:网络
I am new to javascript, but is this valid? <script type=\"text/javascript\"> if (condition()) {

I am new to javascript, but is this valid?

<script type="text/javascript"> 
    if (condition()) { 
        location = "http://example.com/foo/bar/baz"; 
    } 

function condition()
{
if(something)
return true
else
return false
</script> 

I am trying to write a javascript that goes insdie of co开发者_如何学Cntent editer web part inside of SharePoint. Thanks.


It's almost valid (needs a closing }), you can call a function in or as an if() condition.

It should have the } on the end:

function condition() {
  if(something)
    return true;
  else
    return false;
}

Or much simpler:

function condition() {
  return something;
}

You can test it here.


No, your missing a } at the end of your condition function.


No, but this is:

<script type="text/javascript"> 
    if (condition()) { 
        location = "http://example.com/foo/bar/baz"; 
    } 

function condition()
{
  if(something)
    return true;
  else
    return false;
}
</script> 


No, You need a closing curly bracket on your function.

0

精彩评论

暂无评论...
验证码 换一张
取 消