【发布时间】:2015-12-01 19:40:34
【问题描述】:
我正在尝试使用 JQuery 在浏览器窗口上打印一个块。我通过函数将块属性变成了一个JS对象类。在这段代码中,我使用了"use strict"; 方法。
HTML(5):
<!DOCTYPE html>
<html><TITLE>Logo Experiment</TITLE>
<head>
<!--adding JQuery library-->
<!--this is a DESKTOP JQuery, so this will not work much on the modern androids-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!--setting charset to utf-8 unicode in case symbols are needed-->
<meta charset="utf-8">
</head>
<style>
body {
display: block;
}
.bx { /* the box... */
background-image: url("metal.png");
background-size: cover;
background-color: #333333; /* in case the image fails to load */
border-width: 1.5px;
border-radius: 6px;
border-style: solid;
border-color: #222222;
box-shadow: 2px 2px 2px #111111;
}
</style>
<body>
<script>
//the script below
</script>
</body>
</html>
JS/JQuery:
"use strict";
function Box(width, height, style) {//box object
width = this.width;
height = this.height;
style = this.style;
};
var lbx = new Box(256, 256, "bx"); //"lbx" is "logo box"
$(document).ready(function(){//appending a div to the <body> tag directly
$("<div class='" + lbx.style + "' style='width:" + lbx.width + "px;height:" + lbx.height + "px;'>").appendTo("body");
});
每当我尝试使用 JS 对象属性使用 JQuery 附加块时,我都会得到以下输出:<div class="undefined" style="width:undefinedpx;height:undefinedpx;"></div>
非常感谢任何帮助。
此致,CA1K。
【问题讨论】:
标签: javascript jquery html function oop