从 jquery .each 函数返回确认值
我在上传文件的按钮上有一个单击处理程序。它根据预定义值检查表格第一列每个单元格的内容,并且仅在用户确认后继续。我可以让下面的代码工作,但感觉不优雅。有什么建议吗?
$('#upload').click(function() {
var proceed;
$('#mytable tr td:first-child').each(function(a, b) {
if ($(b).html() == 'x') {
proceed = confirm('u sure?');
return false;
}
});
return proceed;
});
编辑:
我想做类似以下的事情,我只是不知道正确的语法(这不起作用):
$('#upload').click(function() {
return $('#mytable tr td:first-child').each(function(a, b) {
if ($(b).html() == 'x') {
return confirm('u sure?');
}
});
});
I have a click handler on a button that uploads a file. It checks the contents of each of the cells of the first column of a table against a predefined value and only proceeds on user confirmation. I can get the below to work but it doesn't feel elegant. Any suggestions?
$('#upload').click(function() {
var proceed;
$('#mytable tr td:first-child').each(function(a, b) {
if ($(b).html() == 'x') {
proceed = confirm('u sure?');
return false;
}
});
return proceed;
});
EDIT:
I want to do something like the following i just dont know the correct syntax (and this doesnt work):
$('#upload').click(function() {
return $('#mytable tr td:first-child').each(function(a, b) {
if ($(b).html() == 'x') {
return confirm('u sure?');
}
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是至少简化代码的一种方法
这是一个 jsfiddle,显示了修改后的代码的实际操作: http:// /jsfiddle.net/Akkuma/R5Mzt/ (更新为更准确)
我刚刚在 IE7、IE9 和 Chrome 中进行了快速测试,发现输入的文件值足够唯一,以至于它无法遇到包含问题。两者都输出 C:\fakepath\nameofile.png。
Here is one way to simplify your code at the very least
Here is a jsfiddle showing the modified code in action: http://jsfiddle.net/Akkuma/R5Mzt/ (updated to be more accurate)
I just ran a quick test in IE7, IE9, and Chrome and found the input's file value to be unique enough that it could not run into a contains problem. Both output C:\fakepath\nameoffile.png.