抱歉这个菜鸟问题......我一直在寻找一个例子,但我显然做错了什么(或者偏离了我想做的事情!)
我正在使用这个: http://www.devx.com/webdev/Article/10483/0/page/2 使用可见性和 div 部分创建多页表单。看起来效果很好。
我现在需要能够从另一页打印(打印机)一页。可能吗?
我正在尝试使用 Jason Day 的 printThis 插件。
我是这样调用插件的: $.getScript("printThis.js", function(){ });
(插件在当前目录中...稍后会解决)
<input type="button" id="B1" value="Go Back" onClick="showLayer('page1')">
<input type="button" id="B2" value="Print App" onClick="$("#page1").printThis()">
第一个按钮按预期工作...返回到第 1 页 第二个按钮什么都不做...语法正确吗?还是我只是想做一些无法完成的事情?
最佳答案
您的第一个按钮 是正确的。然而,第二个按钮 不是。您的 jQuery 选择器中的双引号 "
导致 onClick
属性过早关闭。请尝试以下方法之一:
内联选项 1 - 转义双引号
<input type="button" id="B2" value="Print App" onClick="$(\"#page1\").printThis()">
内联选项 2 - 使用单引号
<input type="button" id="B2" value="Print App" onClick="$('#page1').printThis()">
选项 3 - 删除干扰性 JavaScript(强烈推荐)
<!-- Place this code in the <head></head> section of your page -->
<script type="text/javascript">
$(document).ready(function () {
$('#B2').on('click', function () {
$('#page1').printThis();
});
});
</script>
关于javascript - 如何将 printThis 插件功能分配给按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20496856/