ASP 我的简单 if 语句不起作用
我正在做一个简单的html网站,我写的需要一些php,但是服务器没有php,只有asp。现在我必须学习一点asp。
<li><a id="main-link" <% If selected = "main" Then Repsonse.Write("class='selected'") End If %> href="/home/">main</a></li>
上面的模式代码有什么问题?我读了一些教程,这是我想到的。
I'm doing a simple a simple html site that I wrote which needed some php, however the server does not have php, only asp. Now I have to learn a bit of asp.
<li><a id="main-link" <% If selected = "main" Then Repsonse.Write("class='selected'") End If %> href="/home/">main</a></li>
What is wrong with mode code above? I read some tutorials and that what I came up with.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如@derekaug 已经指出的那样,您有一个拼写错误。然而,通过这里的教育,我会这样做。在页面的早期部分,您将放置一般帮助程序代码(并且可能是分配
selected
变量的位置):然后您的链接看起来像这样,
您显然将拥有多个这些和这个看起来会整洁很多。通过使用函数包含任何逻辑,将分散在 HTML 元素中的实际代码量保持在绝对最低限度始终是一个好主意。
You have a typo as @derekaug has already pointed out. However by way of education here is how I would do it. In an early section of the page where you would put general helper code (and probably where the
selected
variable gets assigned):then your links looks like this
you'll clearly have more than one of these and this would look much tidier. Its always a good idea to keep the amount of actual code dispersed in HTML elements to the absolute minimum by using functions to contain any logic.
您的
Response.Write
代码中有拼写错误,请尝试以下操作:You have a typo in your code for
Response.Write
, try this: