返回到:Prototype – 基本对象
如果存在,此方法返回 obj 到 HTML 方法的返回值,否则通过String.interpret方法运行 obj。
语法
Object.toHTML(obj);
返回值
如果存在,返回 obj 到 HTML 方法的返回值,否则通过String.interpret方法运行 obj。
例子
HTML
x
37
37
1
<html>
2
<head>
3
<title>Prototype examples</title>
4
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
5
6
<script>
7
var Bookmark = Class.create({
8
initialize: function(name, url) {
9
this.name = name;
10
this.url = url;
11
},
12
toHTML: function() {
13
return '<a href = "#{url}">#{name}</a>'.interpolate(this);
14
}
15
});
16
var api = new Bookmark('Prototype', 'http://prototypejs.org');
17
18
function showResult() {
19
alert("Test 1: " + Object.toHTML(api));
20
alert("Test 2: " + Object.toHTML("Hello world!"));
21
alert("Test 3: " + Object.toHTML());
22
alert("Test 4: " + Object.toHTML(null));
23
alert("Test 5: " + Object.toHTML(undefined));
24
alert("Test 6: " + Object.toHTML(true));
25
alert("Test 7: " + Object.toHTML(false));
26
alert("Test 8: " + Object.toHTML(123));
27
}
28
</script>
29
</head>
30
31
<body>
32
<p>Click the button to see the result.</p>
33
<br />
34
<br />
35
<input type = "button" value = "Result" onclick = "showResult();"/>
36
</body>
37
</html>
返回到:Prototype – 基本对象
阅读剩余 51%
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/8662.html