【发布时间】:2016-02-02 23:15:53
【问题描述】:
我想以编程方式向我的网站添加背景图片,但是我遇到的代码不起作用。
首先我使用 Javascript 打印浏览器尺寸:
$(document).ready(function () {
$("#clientScreenWidth").val($(window).width());
$("#clientScreenHeight").val($(window).height());
});
之后,我通过隐藏输入将这些维度发送到 vb.net 并为其分配值:
Dim height As String = HttpContext.Current.Request.Params("clientScreenHeight")
Dim width As String = HttpContext.Current.Request.Params("clientScreenWidth")
但是,当我尝试将这些参数输入到字符串中并将其传递给我身体的 css 时,出现了错误:
Dim BackgroundImageURL As String = "https://unsplash.it/" + height + "/" + width
body.Style.Add("background-image: url(""" + BackgroundImageURL + """);")
重载解析失败,因为没有可访问的“添加”接受此数量的参数。
编辑:
发帖说我修复了过载解决错误!
语法是"classid.style.add("first part of css name", "second part")"
示例:body.style.add("background-image", "url(""http://google.com/logo.png"")")
【问题讨论】:
-
查看 Style.Add 的文档,虽然我不确定你为什么不全部使用 JavaScript/jQuery。
-
谢谢。我会用 JS 来做,很难相信我忽略了这么简单的一步!
标签: javascript html css asp.net vb.net