对于HTML标签属性,如果不加引号,则编译时会提示“验证(XHTML 1.0 Transitional): 特性值前后必须加引号”的警告信息,并且生成为HTML属性也确实没有加上引号,那么虽然属性后面确实是没有加上引号的正确的绑定值,但是不一定能展示出想要看到的结果。比如对于input标签的value属性,如果绑定的字符串是" hello world from variable”,则在客户端的input显示出的内容实际上只是"hello”字符串,生效的属性值是一个被截断的字符串,它从属性后的一串字符串(若未加引号)的第一个非空字符开始,截止到下一个空字符的前一个字符为止(比如对于" hello world”,结果将是"hello”),因此,加上引号是必须的。
public partial class WebForm2 : System.Web.UI.Page
{
public string GetVariableStr;//注意变量的修饰符
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetVariableStr = "hello world from variable";
}
}
protected string GetFunctionStr()//注意返回值的修饰符
{
return "hello world from Function";
}
}
前台代码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function fun() {
public partial class WebForm2 : System.Web.UI.Page
{
public string GetVariableStr;
public ArrayList arraylist;
public DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetVariableStr = "hello world from variable";
arraylist = new ArrayList();
arraylist.Add("选?项?1");
arraylist.Add("选?项?2");