<div class="pages"> <span>显示</span> <select class="combox" name="numPerPage" onchange="navTabPageBreak({numPerPage:this.value}, 'jbsxBox')"> <option value="20">20</option> <option value="50">50</option> <option value="100">100</option> <option value="200">200</option> </select> <span>条,共50条</span> </div>
这样写在浏览器查看源文件没有问题
但是在mvc中 我换成下面这种写法
<div class="pages"> <span>显示</span> @Html.DropDownList("numPerPage", ViewData["numPerPage"] as SelectList, new { @class = "combox", onchange = "navTabPageBreak({numPerPage:this.value},'jbsxBox')" }) <span>条,共 @ViewData["recordCount"]条</span> </div>
查看源文件 onchange="navTabPageBreak({numPerPage:this.value},'jbsxBox')" 变成了这样
而导致我的js调用出错 怎么让他显示' 不要 弄成'这样
<script type="text/javascript"> $(function () { $("#numPerPageStuClass").change(function () { navTabPageBreak({ numPerPage: this.value }, 'jbsxBox'); }); }); </script>
在解析的时候会被默认的编码,不必纠结在这种问题,完全可以利用Jquery来绕过
@Html.Raw(Html.DropDownList("numPerPage", ViewData["numPerPage"] as SelectList, new { @class = "combox", onchange = "navTabPageBreak({numPerPage:this.value},'jbsxBox')" }))
这样包一下
没有任何效果 还是一样
并且语法错误
onchange="navTabPageBreak({numPerPage:this.value},'jbsxBox')"
这种方式不影响JS调用的啊
如果你一定想要单引号的方式可以这样写:
@Html.Raw(Html.DropDownList("numPerPage", ViewData["numPerPage"] as SelectList, new { @class = "combox", onchange = "navTabPageBreak({numPerPage:this.value},'jbsxBox')" }).ToHtmlString().Replace("'","'"))
onchange="navTabPageBreak({numPerPage:this.value},'jbsxBox')"
会影响js的调用 要不然我问这个问题干嘛
@bcacyy: 你看看这个页面:
http://jscode.chinacxy.com/code/905aef4e11cb2ef11a0ce65974f89ff1.aspx
@Html.Raw(Html.DropDownList("numPerPage", ViewData["numPerPage"] as SelectList, new { @class = "combox", onchange = "navTabPageBreak({numPerPage:this.value},'jbsxBox')" }).ToHtmlString().Replace("'","'"))
同样无任何效果 还是被编码成'了