源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

ASP.NET MVC中使用JavaScriptResult的用法示例

  • 时间:2021-01-21 08:59 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:ASP.NET MVC中使用JavaScriptResult的用法示例
本文实例讲述了ASP.NET MVC中使用JavaScriptResult的用法。分享给大家供大家参考,具体如下: 在页面中我们使用JavaScript来设置id为qubernet的span标签样式,具体代码如下: JS:
<script>
    $(function () {
      var thisObj = document.getElementById("qubernet");
      thisObj.setAttribute("style", "color:#f00;font-size:22px;");
    });
</script>

Html:
<body>
  <span id="qubernet">qubernet span!!!</span>
</body>

运行效果: [img]http://files.jb51.net/file_images/article/201608/201686102620307.png?201676102650[/img] 以上的效果我们也可以使用MVC中的JavaScriptResult来实现,具体如下: 控制器方法:
[HttpPost]
public JavaScriptResult GetJavaScriptResult()
{
  const string thisJs = "var thisObj = document.getElementById(\"qubernet\");thisObj.setAttribute(\"style\",\"color:#f00;font-size:22px;\");";
  return JavaScript(thisJs);
}

JS:
<script>
$(function () {
  $.ajax({
    type: "post",
    url: "/QuberManage/SysLogin/GetJavaScriptResult"
  });
});
</script>

Html:
<body>
  <span id="qubernet">qubernet span!!!</span>
</body>

注:这里使用到了jQuery的ajax方法,当然需要引入jQuery库了,你懂得 更多关于asp.net相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/737.htm]asp.net优化技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/692.htm]asp.net字符串操作技巧汇总[/url]》、《[url=http://www.1sucai.cn/Special/660.htm]asp.net操作XML技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/306.htm]asp.net文件操作技巧汇总[/url]》、《[url=http://www.1sucai.cn/Special/535.htm]asp.net ajax技巧总结专题[/url]》及《[url=http://www.1sucai.cn/Special/626.htm]asp.net缓存操作技巧总结[/url]》。 希望本文所述对大家asp.net程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部