【发布时间】:2012-03-03 14:53:50
【问题描述】:
我正在开发一个网站。基本上,我的网站中有两个脚本。第一个脚本执行得很好。但是,第二个脚本不起作用。
基本上,我想要做的是,如果用户点击一个按钮,页面上的某些元素会被隐藏,而其他元素会被显示。有问题的元素是表格(不是 asp 表格)。
这里是代码。
<script type="text/javascript">
function Open_Window()
{
window.open("DonationConfirmation.aspx")
}
</script>
<script type="text/javascript">
$(document).ready(function () {
$("#PayPalButton1").click(function () {
$("#PayPalTableButton").show();
$("#DonationsTableButton").hide();
});
$("#GoogleButton1").click(function () {
$("#PayPalTableButton").hide();
$("#DonationsTableButton").show();
});
});
</script>
第一个脚本,即函数Open_Window() 运行良好。
但是,用 jQuery 编写的第二个脚本不起作用。
这是按钮(以图像的形式)和表格的代码。
<asp:Image ID="PayPalButton1" runat="server" ImageUrl="Resources/Icons/PayPal.jpg" onmouseover="this.style.cursor = 'pointer';" Height="65px" Width="130px" />
<asp:Image ID="GoogleButton1" runat="server" ImageUrl="Resources/Icons/Google.jpg" onmouseover="this.style.cursor = 'pointer';" Height="65px" Width="130px" />
<table id="PayPalTableButton" runat="server" style="margin:auto; text-align:center; width:100%;">
<tr>
<td style="text-align:center; height:60px;">
//Code
</td>
</tr>
</table>
<table id="DonationsTableButton" runat="server" style="margin:auto; text-align:center; width:100%;">
<tr>
<td style="text-align:center; height:60px;">
//Code
</td>
</tr>
</table>
【问题讨论】:
-
“不起作用”是什么意思?您是否使用错误控制台查看代码是否正在执行但出现错误?您是否在 jquery 包装器中抛出了“警报”以查看它是否正在执行?你有jquery加载吗?更多细节 - 特别是在 javascript 领域,这将更容易回答。
-
基本上,在我的母版页中,我有以下行: By doesn't work ,我的意思是当我单击两个按钮中的任何一个(即 PayPalButton1 和 GoogleButton1)时,根本不会发生任何事情。表格未隐藏/显示。一切都保持不变,就好像没有发生点击事件一样。
-
我建议编辑问题以包含它。但是,您需要调试脚本。我建议在 Firefox 中运行,然后启动 Tools->Developer Tools->Error Console 并查看发生了什么。根据这个问题,我们无法判断您的 jQuery 是否正在加载。您必须先建立该部分,然后我们可以帮助调试您拥有的代码。
-
我按照建议在打开错误控制台的情况下运行了网站。错误控制台中什么也没有出现。
标签: jquery image button html-table