在JSFiddle上工作,但不在本地工作
Works on JSFiddle but not locally?
这个jsfiddle对我来说很好http://jsfiddle.net/xzZ7n/1/
但是,当我尝试在本地或从Sharepoint运行它时,当我按下pdf按钮时,什么都不会发生
知道为什么会这样吗
这是我的代码:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> - jsFiddle demo</title>
<script type='text/javascript' src='//code.jquery.com/jquery-git.js'></script>
<link rel="stylesheet" type="text/css" href="/css/result-light.css">
<script type='text/javascript' src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<script type='text/javascript' src="http://mrrio.github.io/jsPDF/dist/jspdf.debug.js"></script>
<style type='text/css'>
</style>
</head>
<body>
<div id="customers">
<table id="tab_customers" class="table table-striped">
<colgroup>
<col width="20%">
<col width="20%">
<col width="20%">
<col width="20%">
</colgroup>
<thead>
<tr class='warning'>
<th>Country</th>
<th>Population</th>
<th>Date</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<tr>
<td>Chinna</td>
<td>1,363,480,000</td>
<td>March 24, 2014</td>
<td>19.1</td>
</tr>
<tr>
<td>India</td>
<td>1,241,900,000</td>
<td>March 24, 2014</td>
<td>17.4</td>
</tr>
<tr>
<td>United States</td>
<td>317,746,000</td>
<td>March 24, 2014</td>
<td>4.44</td>
</tr>
<tr>
<td>Indonesia</td>
<td>249,866,000</td>
<td>July 1, 2013</td>
<td>3.49</td>
</tr>
<tr>
<td>Brazil</td>
<td>201,032,714</td>
<td>July 1, 2013</td>
<td>2.81</td>
</tr>
</tbody>
</table>
</div>
<button onclick="javascript:demoFromHTML();">PDF</button>
<script type='text/javascript'>//<![CDATA[
function demoFromHTML() {
var pdf = new jsPDF('p', 'pt', 'letter');
// source can be HTML-formatted string, or a reference
// to an actual DOM element from which the text will be scraped.
source = $('#customers')[0];
// we support special element handlers. Register them with jQuery-style
// ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
// There is no support for any other type of selectors
// (class, of compound) at this time.
specialElementHandlers = {
// element with id of "bypass" - jQuery style selector
'#bypassme': function (element, renderer) {
// true = "handled elsewhere, bypass text extraction"
return true
}
};
margins = {
top: 80,
bottom: 60,
left: 40,
width: 522
};
// all coords and widths are in jsPDF instance's declared units
// 'inches' in this case
pdf.fromHTML(
source, // HTML string or DOM elem ref.
margins.left, // x coord
margins.top, { // y coord
'width': margins.width, // max width of content on PDF
'elementHandlers': specialElementHandlers
},
function (dispose) {
// dispose: object with X, Y of the last line add to the PDF
// this allow the insertion of new lines after html
pdf.save('Test.pdf');
}, margins);
}
//]]>
</script>
</body>
</html>
知道为什么不起作用吗?谢谢
<head />
中包含的大多数依赖URL都已损坏,因为您省略了其中的一部分:您需要添加一些http://
才能获得有效的远程URL。
here ------|
<head> v
<script type='text/javascript' src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<!-- Same thing for other libraries you use... -->
</head>
此外,您还忘记在<head>
标记的开头包含jQuery。
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-git.js"></script>
</head>
相关文章:
- 代码只能在jsfiddle中工作
- JavaScript获胜't运行,但在jsFiddle中工作
- 为什么jquery悬停在jsfiddle中可以工作,而在我的html布局中却不能
- 我需要把jsFiddle的脚本放到工作中
- 代码在jsfiddle中工作,但在本地服务器中不起作用
- 尝试让AngularJS在JSFiddle中工作
- jQuery和其他从工作的jsfiddle复制到本地env时未运行的JS
- 在JSFiddle上工作,但不在本地工作
- 可以'我似乎无法让这个jsfiddle在本地工作.
- 为什么我的JSFiddle不工作?(放置脚本的位置)
- 正在jsfiddle.net上工作,但不在我的笔记本电脑上
- 为什么jQuery可以在jSfiddle中工作,但不能在站点中工作
- 当我尝试在jsFiddle中暂停并播放时,我的代码可以工作,但它不起作用;我的html页面不起作用
- 我如何才能让我的代码像在jsfiddle中一样工作
- jsFiddle工作,网站JS不工作
- 代码在 jsfiddle 中工作,但在我的网站上不起作用
- 我的jQuery在JSFiddle中工作,但不能在我的网站上工作!我做错了什么
- jQuery, bootstrap: input.val() 是未定义的,即使 jsfiddle 工作正常
- jQuery适用于JSFiddle,但不能在本地工作
- 代码工作 jsfiddle 不适用于 dreamweaver