jQuery 你确定你要删除?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1989572/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Are you sure you want to delete?
提问by Phillip Senn
I just wrote a confirm delete function that requires a class name:
我刚刚写了一个需要类名的确认删除函数:
jQuery(document).ready(function($) {
$('.ConfirmDelete').click(function() {
var question = $(this).attr('title');
if (question == '') question = 'Delete this record?';
return confirm(question);
});
});
Usage:
用法:
<input name="Delete" type="submit" value="Delete" class="ConfirmDelete" title="Delete #UsrName#?" />
I'd like to change the selector from .ConfirmDelete to something like:
我想将选择器从 .ConfirmDelete 更改为:
$('input:submit').attr('name','Delete').val('Delete')
Meaning: If a submit button has the name 'Delete' and it's value is 'Delete', then go ahead and assume they want to confirm the delete without requiring them to have a ConfirmDelete class.
含义:如果提交按钮的名称为“Delete”并且其值为“Delete”,则继续假设他们想要确认删除而不要求他们拥有 ConfirmDelete 类。
回答by David Hellsing
$(':submit[name="Delete"][value="Delete"]').click(function() {
return window.confirm(this.title || 'Delete this record?');
});
回答by Sampson
The following would apply to all present, and future instances of any submit button having both the name and value of "Delete":
以下将适用于所有具有“删除”名称和值的提交按钮的所有当前和未来实例:
$(function(){
$(":submit[name='Delete'][value='Delete']").live("click", function(e){
e.preventDefault(); // remove if not necessary
// Seriously, delete it.
});
});
回答by Mickel
Something like this maybe?
也许像这样的东西?
$('input:submit[name="Delete"][value="Delete"]')
回答by BalusC
Your question is a bit vague, but if I interpret it correctly, you actually want to know the syntax to select a input type="submit" name="Delete" value="Delete"
in jQuery?
你的问题有点含糊,但如果我解释正确,你真的想知道input type="submit" name="Delete" value="Delete"
在 jQuery 中选择 a 的语法吗?
If so, here it is:
如果是这样,这里是:
$('input:submit[name="Delete"][value="Delete"]')