打印按钮不起作用

时间:2016-04-16 16:24:13

标签: javascript html

我为自己的网页创建的打印按钮无效。当我检查元素时,似乎没有任何结果出来。没有一个错误

这是我的HTML代码:

<button onclick = "printAddOrders()">Print New Orders</button>

这是javascript函数代码:

function printNewOrders(){
  window.print();
}

$(document).on("click", "#print-click", printNewOrders);

这里还附有一​​个指向我的JSFiddle的链接,我为了展示而模拟了问题以使事情变得更加清晰:

https://jsfiddle.net/poch_MENDOZA/7uwm8sd0/

6 个答案:

答案 0 :(得分:1)

您可以从按钮拨打updating specific remote refs along with associated objects。我想你的意思是打电话给printAddOrders()

答案 1 :(得分:1)

您忘记将print-click ID添加到<button>

<button id="print-click" onclick="printAddOrders()">

你的功能名称并不重合。您在html中有printAddOrders,在js中有printNewOrders

这是你工作的小提琴的a fork

答案 2 :(得分:1)

您既没有定义 public void initConnection(String user, String pass) throws XMPPException { // TODO Auto-generated method stub String SERVER_HOST = "192.168.1.199"; int SERVER_PORT = 5222; String SERVICE_NAME = "Allen"; try { if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder() .permitAll().build(); StrictMode.setThreadPolicy(policy); } XMPPTCPConnectionConfiguration.Builder connConfig = XMPPTCPConnectionConfiguration .builder(); connConfig .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled); connConfig.setUsernameAndPassword(user, pass); connConfig.setServiceName(SERVICE_NAME); connConfig.setHost(SERVER_HOST); connConfig.setPort(SERVER_PORT).setCompressionEnabled(false); connConfig.setDebuggerEnabled(true); connConfig.setConnectTimeout(25000); XMPPTCPConnectionConfiguration configuration = connConfig.build(); // XMPPTCPConnection.setUseStreamManagementDefault(true); // XMPPTCPConnection.setUseStreamManagementResumptiodDefault(true); // XMPPTCPConnection.setReplyToUnknownIqDefault(true); connection = new XMPPTCPConnection(configuration); connection.setUseStreamManagement(true); connection.setUseStreamManagementResumption(true); connection.setReplyToUnknownIq(true); connection.setPacketReplyTimeout(25000); ReconnectionManager manager = ReconnectionManager.getInstanceFor(connection); manager.setFixedDelay(15); ReconnectionManager.setDefaultReconnectionPolicy(ReconnectionManager.ReconnectionPolicy.FIXED_DELAY); manager.enableAutomaticReconnection(); try { connection.connect(); connection.login(); //logIn(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (Exception ex) { ex.printStackTrace(); } } 也没定义printNewOrdersprintAddOrders已附加onclick,但没有功能正文。

其次,没有ID printAddOrders附加到任何DOM元素。

您的jsfiddle无法使用$,但未包含print-click

下面是点击按钮时打开jquery的鳕鱼片段。你这里不需要jquery

<强> HTML

print window

<强> JS

<button onclick = "printAddOrders()" id ="print-click">Print New Orders</button>

jsfiddle without jquery

使用jquery的片段

<强> HTML

 function printAddOrders(){
  window.print();
}

<强> JS

// Note there is no onclick handler added since you are delegating the event to click of `print-click`
<button onclick = "" id ="print-click">Print New Orders</button>

jsfiddle with jquery

答案 3 :(得分:0)

尝试

<button onclick = "window.print()">Print New Orders</button>

答案 4 :(得分:0)

printNewOrders()

你想要完成吗?或者你需要更多的打印功能?

答案 5 :(得分:0)

整个代码供您参考:

function printNewOrders(){window.print(); }

由于