Jquery 编写此标记的其他方法
有没有其他方法来写上面的内容?唯一的区别在于是否根据条件显示 谢谢,Jquery 编写此标记的其他方法,jquery,asp.net-mvc,Jquery,Asp.net Mvc,有没有其他方法来写上面的内容?唯一的区别在于是否根据条件显示 谢谢, rodchar这里有另一种方式,但我不确定我是否比原来的更喜欢它;) 也许还有一个更短的符号。尽管jrrnS示例会起作用,但您可能需要考虑把它放在一个扩展方法:中。 <%= Html.Results(isTrue) %> 在你图书馆的一个班级里: public static class MyHtmlExtensions public static string Results(this Html
rodchar这里有另一种方式,但我不确定我是否比原来的更喜欢它;)
也许还有一个更短的符号。
尽管jrrnS示例会起作用,但您可能需要考虑把它放在一个扩展方法:中。<%= Html.Results(isTrue) %>
在你图书馆的一个班级里:
public static class MyHtmlExtensions
public static string Results(this HtmlHelper helper, bool hidden)
{
return String.Format("<div id=""myResults"" {0}>",
hidden = ? "style=""display: none;""" : "");
}
}
公共静态类MyHtmlex
公共静态字符串结果(此HtmlHelper帮助程序,布尔隐藏)
{
返回String.Format(“”,
隐藏=?“style=”显示:无;“”:“”);
}
}
由于您使用了样式,您可以将其从html正文中完全删除
<style type="text/css">
div#myResults { display: <$= isTrue ? "none" : "block" %>; }
</style>
...
<div id=myResults>
div#myResults{display:;}
...
<%= Html.Results(isTrue) %>
public static class MyHtmlExtensions
public static string Results(this HtmlHelper helper, bool hidden)
{
return String.Format("<div id=""myResults"" {0}>",
hidden = ? "style=""display: none;""" : "");
}
}
<style type="text/css">
div#myResults { display: <$= isTrue ? "none" : "block" %>; }
</style>
...
<div id=myResults>