我在下面有以下函数,当所有 3 个变量都不为空时它工作得很好,但是,如何修改它以便当任一变量(电话、传真、单元格)为空时,包含空变量的行不会得到书面?
Current scenario:
T. 123-4567-8910
F. 987-654-3210
C.
-------------------------------
Desired scenario:
T. 123-4567-8910
F. 987-654-3210
-------------------------------
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function test() {
var tel = "123-4567-8910"
var fax = "987-654-3210"
var cell = ""
var html =
'<div>T. '+ tel +'</div>\n' +
'<div>F. '+ fax +'</div>\n' +
'<div>C. '+ cell +'</div>'
document.write(html)
}
</script>
</head>
<body>
<a href="javascript:test()">test</a>
</body>
</html>