当确认对话框返回false时保持行可见
Keep row visible when confirm dialog returns false
嗨,我有一个包含行的表。当页面加载时,我隐藏了奇数行(它们包含详细信息)。当我单击行(偶数)时,它显示下一行(包含详细信息的行)。请参阅jsfiddle示例。
HTML:<table>
<tr>
<th>Name</th>
<th>Title</th>
<th>Details</th>
</tr>
<tr>
<td>Faisal</td>
<td>Applicaiton Developer</td>
<td>Work in Aid</td>
</tr>
<tr>
<td colspan="2">this is Faisal Details</td>
<td>
<input type="button" value="Approve" class="approve" />
<input type="button" value="Deny" class="deny" />
<input type="button" value="Cancel" class="cancel" />
</td>
</tr>
<tr>
<td>Fabrizio </td>
<td>Applicaiton Developer</td>
<td>Work in Aid</td>
</tr>
<tr>
<td colspan="2">this is Fabrizio </td>
<td>
<input type="button" value="Approve" class="approve" />
<input type="button" value="Deny" class="deny" />
<input type="button" value="Cancel" class="deny" />
</td>
</tr>
<tr>
<td>Kelly </td>
<td>Applicaiton Developer</td>
<td>Work in Aid</td>
</tr>
<tr>
<td colspan="2">this is Kelly </td>
<td>
<input type="button" value="Approve" class="approve" />
<input type="button" value="Deny" class="deny" />
<input type="button" value="Cancel" class="deny" />
</td>
</tr>
<tr>
<td>Hillary </td>
<td>Applicaiton Developer</td>
<td>Work in Aid</td>
</tr>
<tr>
<td colspan="2">this is Hillary </td>
<td>
<input type="button" value="Approve" class="approve" />
<input type="button" value="Deny" class="deny" />
<input type="button" value="Cancel" class="deny" />
</td>
</tr>
<tr>
<td>Krista </td>
<td>Applicaiton Developer</td>
<td>Work in Aid</td>
</tr>
<tr>
<td colspan="2">this is Krista </td>
<td>
<input type="button" value="Approve" class="approve" />
<input type="button" value="Deny" class="deny" />
<input type="button" value="Cancel" class="deny" />
</td>
</tr>
<tr>
<td>Justin </td>
<td>Applicaiton Developer</td>
<td>Work in Aid</td>
</tr>
<tr>
<td colspan="2">this is Justin </td>
<td>
<input type="button" value="Approve" class="approve" />
<input type="button" value="Deny" class="deny" />
<input type="button" value="Cancel" class="deny" />
</td>
</tr>
<tr>
<td>Eric </td>
<td>Applicaiton Developer</td>
<td>Work Aid</td>
</tr>
<tr>
<td colspan="2">this is Eric </td>
<td>
<input type="button" value="Approve" class="approve" />
<input type="button" value="Deny" class="deny" />
<input type="button" value="Cancel" class="deny" />
</td>
</tr>
<tr>
<td>Faisal </td>
<td>Applicaiton Developer</td>
<td>Work inAid</td>
</tr>
<tr>
<td colspan="2">this is Faisal Details</td>
<td>
<input type="button" value="Approve" class="approve" />
<input type="button" value="Deny" class="deny" />
<input type="button" value="Cancel" class="deny" />
</td>
</tr>
</table>
jquery: $("table tr:nth-child(odd)").css("display", "none");
var prevRowIndex;
$("table tr:not(:first-child)").click(function (e) {
if (prevRowIndex != undefined) {
$(prevRowIndex).css("display", "none");
prevRowIndex = null;
}
var styles = {
"border": "#000",
"margin-bottom": "10px"
};
prevRowIndex = $(this).next();
//$(this).css("z-index", "9999");
$(this).next().slideDown('slow');
});
$(".approve").click(function (e) {
if (confirm("Are you sure you would like to approve this request?") == false) {
e.preventDefault();
$(this).parents("tr").css("display", "block");
}
});
$(".deny").click(function (e) {
if (confirm("Are you sure you would like to deny this request?") == false) {
$(this).parents("tr").css("display", "block");
e.preventDefault();
}
});
$(".cancel").click(function (e) {
if (confirm("Are you sure you would like to cancel this request?") == false) {
$(this).parents("tr").css("display", "block");
e.preventDefault();
}
});
当一个按钮被点击时(在细节行中),它首先请求确认。我的问题是当我在确认对话框中选择"取消"时,它隐藏了详细信息行。
我希望我已经解释清楚了。如有任何帮助,不胜感激。jsfiddle示例
OK -您没有停止propagation
,因此即使您单击按钮并删除/隐藏按钮所在的行,第一个侦听器$("table tr:not(:first-child)").click(function (e) {
也会被触发。
这将工作。
$(".approve").click(function (e) {
if (confirm("Are you sure you would like to approve this request?") == false) {
e.stopPropagation();
}
});
$(".deny").click(function (e) {
if (confirm("Are you sure you would like to deny this request?") == false) {
e.stopPropagation();
}
});
$(".cancel").click(function (e) {
if (confirm("Are you sure you would like to cancel this request?") == false) {
e.stopPropagation();
}
});
演示:http://jsfiddle.net/robschmuecker/7Q79g/
相关文章:
- 删除确认对话框在第一次单击时不起作用
- javascript确认对话框有时会不断出现
- 如何为javascript方法放入jquery确认对话框
- 是否可以将JXBrowser显示的JS确认对话框的结果返回到调用它的JS部分
- 如何在批准露天共享中工作流的审核步骤之前添加确认对话框
- MVC3 Ajax链接确认对话框使用jquery ui对话框
- 是否可以隐藏javascript确认对话框
- Javascript/C# - 满足语句条件时的确认对话框
- 提交表单前使用确认对话框的正确方法
- 在浏览器关闭时,单击确认对话框中的“停留在页面上”,执行一个方法
- 确认对话框多次触发
- 为什么JS confirm()获胜't当我在确认对话框中点击“取消”时,取消提交操作
- onbeforeunload确认对话框可以用设计良好的自定义对话框进行自定义
- 是否有任何方法可以在单击“加载前确认”对话框的“确定”按钮后执行某些操作
- 如何处理JavaScript's GridView上的确认对话框's PageIndexChanging
- 如何在jquery确认对话框中使用回调
- 如何在 asp.net 中的页面加载事件之前调用 JavaScript 确认对话框
- 在道场中确认对话框
- 按下 X 之前的 JavaScript 确认对话框
- JAWS 屏幕阅读器误读确认对话框消息.IE11.