asp.net - 按钮不会执行功能onclick
问题描述:
我已经通过某人的帮助取得了这段代码,并希望它在点击#print_button
后执行。出于某种原因,我无法让它工作,我不知道我哪里出错了?asp.net - 按钮不会执行功能onclick
这是jQuery的:
$(document).ready(function() {
$('#Print_Button').click(function() {
var html2obj = html2canvas($('#form1'));
var queue = html2obj.parse();
var canvas = html2obj.render(queue);
var img = canvas.toDataURL();
window.open(img);
});
});
和HTML属性我的按钮:
id="Print_Button" runat="server" value="Print"
任何人都可以请建议我要去的地方错了吗?
这是对身体的完整HTML:
<form id="form1" runat="server">
<div class="header">
<strong class="auto-style11">
MCN PRINTOUT
</strong>
<img alt="Veolia Logo" class="logo" src="logo.png" />
<input type="button" id="Print_Button" value="click me"/>
</div>
<div id="nav">
<ul>
<li><a href="login.aspx">Home</a></li>
<li><a href="MCNForm.aspx">MCN Entry</a></li>
<li><a href="Search.aspx">MCN Search</a></li>
</ul>
</div>
<div id ="main">
<p id ="main_header"></p>
<p id ="mcn">DISPOSAL ADVICE/TRANSFER NOTE</p>
<p id="address">
</p>
<table id="table_1"">
<tr>
<td class="auto-style12">MCN Ref No.</td>
<td>
<asp:TextBox ID="TextBox1" ReadOnly="True" runat="server" Width="116px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style12">Date:</td>
<td>
<asp:TextBox ID="TextBox4" ReadOnly="True" runat="server" Width="116px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style12">Time:</td>
<td>
<asp:TextBox ID="TextBox5" runat="server" ReadOnly="True" Width="116px"></asp:TextBox>
</td>
</tr>
</table>
<img alt="Logo" class="auto-style10" src="logo.png" /><div id ="form">
<table id="main_table" class = "table table-bordered">
<tr>
<td class="auto-style8">SITE:</td>
<td class="auto-style9">
<asp:TextBox ID="TextBox6" runat="server" OnTextChanged="TextBox6_TextChanged" ReadOnly="True"></asp:TextBox>
</td>
<td class="auto-style4">HAULIER(CARRIER):</td>
<td>
<asp:TextBox ID="TextBox10" runat="server" ReadOnly="True"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style8">DESCRIPTION OF WASTE:</td>
<td class="auto-style9">
<asp:TextBox ID="TextBox7" runat="server" ReadOnly="True"></asp:TextBox>
</td>
<td class="auto-style4">DESTINATION:</td>
<td>
<asp:TextBox ID="TextBox9" runat="server" ReadOnly="True"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style8">EWC CODE:</td>
<td class="auto-style9">
<asp:TextBox ID="TextBox8" runat="server" ReadOnly="True"></asp:TextBox>
</td>
<td class="auto-style4">VEHICLE REGISTRATION:</td>
<td>
<asp:TextBox ID="TextBox11" runat="server" ReadOnly="True"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style8">QUANTITY:</td>
<td class="auto-style9">
<asp:TextBox ID="TextBox13" runat="server" ReadOnly="True"></asp:TextBox>
</td>
<td class="auto-style4">DRIVER NAME:</td>
<td>
<asp:TextBox ID="TextBox12" runat="server" ReadOnly="True"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style8">NOMINAL WEIGHT:</td>
<td class="auto-style9">
<asp:TextBox ID="TextBox15" runat="server" ReadOnly="True"></asp:TextBox>
</td>
<td class="auto-style4">SKIP ID:</td>
<td>
<asp:TextBox ID="TextBox16" runat="server" ReadOnly="True"></asp:TextBox>
</td>
</tr>
</table>
<table id="table_2" style="width:30%;">
<tr>
<td>DUTY OF CARE:</td>
<td>
<asp:TextBox ID="TextBox14" runat="server" OnTextChanged="TextBox14_TextChanged"></asp:TextBox>
</td>
</tr>
</table>
</div>
<p id="tsandcs">
</p>
</div>
<div class="footer">
<p id ="footer_menu">Menu</p>
<p id="copyright">© 2017 ...</p>
</div>
</form>
答
使用输入型按钮
$(document).ready(function() {
$('#Print_Button').click(function() {
alert("Clicked");
//your code here
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="button" id="Print_Button" value="click me"/>
+0
嗨@Sandeep Bhaskar,你提出的警报将起作用,但不是它自己的功能,它已经在这里的另一篇文章中为其他人工作。我在原帖中发布了完整的HTML。 – kehoewex86
没有什么不对您的onclick事件。尝试提醒你会看到一个警告框..我认为别的是错误的..发布完整的html代码 – neophyte
@neophyte,请参阅完整的HTML添加上面,已尝试下面的建议,仍然无法正常工作。 – kehoewex86
这个提示肯定是按照@Sandeep Bhaskar的建议工作的,所以必须是之后的Jquery,但是当它为其他人工作时,无法确定它出错的位置。 – kehoewex86