大家好!
我正在为一个带有JavaScript的网站编写一个琐事游戏,该网站在单个多维数组中存储所有问题文本,答案和难度级别,有时我需要将书名用斜体字书写。但是,我在使用斜体时遇到了麻烦。
我喜欢使用HTML标签来执行此操作,但它们只是在屏幕上打印:
public func scrollViewDidZoom(scrollView: UIScrollView) {
let imageViewSize = imageView.frame.size
let scrollViewSize = scrollView.bounds.size
let verticalPadding = imageViewSize.height < scrollViewSize.height ? (scrollViewSize.height - imageViewSize.height) / 2 : 0
let horizontalPadding = imageViewSize.width < scrollViewSize.width ? (scrollViewSize.width - imageViewSize.width) / 2 : 0
if verticalPadding >= 0 {
// Center the image on screen
scrollView.contentInset = UIEdgeInsets(top: verticalPadding, left: horizontalPadding, bottom: verticalPadding, right: horizontalPadding)
} else {
// Limit the image panning to the screen bounds
scrollView.contentSize = imageViewSize
}
}
我还尝试将每个标题变成字符串变量并使用String italics()方法,如下所示:
The title of the books is <i>I Wish I were in Italics!</i>
产生与上述相同的结果。 HTML标记在页面上显示为文本。
有谁知道如何解决这个问题?谢谢!
-ThatsIsJustCrazy
**编辑:我正在使用JQuery将文本插入我的HTML文件中:
var italicsTest = "I Wish I were in Italics!";
Question = ["1", "2", "1824", "The title is" + italicsTest.italics()];
但我应该使用“html”而不是“text”。它需要是这样的:
$(".questionText").text(Question[randomNum1][randomNum2]);
谢谢大家!
答案 0 :(得分:2)
试试这个:
var italicsTest = "I Wish I were in Italics!";
var Question = ["1", "2", "1824", "The title is " + italicsTest.italics()];
$(document).ready(function() {
$.each(Question, function(index){
$("<p>"+Question[index]+"</p>").appendTo($('#content'));
});
});
on jsfiddle