javascript 使用jQuery的多重选择器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3645063/
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
Multiple selector using jQuery
提问by Ibrahim Azhar Armar
i am using a jquery plugin and my code look somthing like this.
我正在使用 jquery 插件,我的代码看起来像这样。
<script type="text/javascript">
$(document).ready(function() {
$('#fileUpload').uploadify({
'uploader': 'img/uploadify.swf',
'script': 'uploadify.php',
'folder': 'upload',
'auto' : 'true',
'cancelImg': 'img/cancel.png',
'fileDesc': 'jpg/jpeg',
'displayData': 'percentage',
'fileExt': "*.jpg;*.jpeg",
'sizeLimit' : '8388608',
'fileDataName' : 'file',
onComplete: function(event, queueID, fileObj, reposnse, data)
{
$('#filesUploaded').append('<a href='+fileObj.filePath+'>'+fileObj.name+'</a><br>');
$("#firstUpload").remove();
}
}); });
$(document).ready(function() {
$('#fileUpload2').uploadify({
'uploader': 'img/uploadify.swf',
'script': 'uploadify.php',
'folder': 'upload',
'auto' : 'true',
'cancelImg': 'img/cancel.png',
'fileDesc': 'jpg/jpeg',
'displayData': 'percentage',
'fileExt': "*.jpg;*.jpeg",
'sizeLimit' : '8388608',
'fileDataName' : 'file',
onComplete: function(event, queueID, fileObj, reposnse, data)
{
$('#filesUploaded').append('<a href='+fileObj.filePath+'>'+fileObj.name+'</a><br>');
$("#firstUpload").remove();
}
}); });
</script>
did you notice that i am using the exact same function and i am just changing the div name, ain't that ridiculous ? now i want my jquery function to accept two div parameters. can i do that?
您是否注意到我正在使用完全相同的功能,而我只是在更改 div 名称,这不是很荒谬吗?现在我希望我的 jquery 函数接受两个 div 参数。我可以吗?
thank you..
谢谢..
回答by BoltClock
Combine the two selectors, just like in CSS:
结合两个选择器,就像在 CSS 中一样:
$(document).ready(function() {
$('#fileUpload, #fileUpload2').uploadify({
...
});
});
回答by Yanick Rochon
<script type="text/javascript">
$(document).ready(function() {
$('#fileUpload,#fileUpload2').uploadify({
'uploader': 'img/uploadify.swf',
'script': 'uploadify.php',
'folder': 'upload',
'auto' : 'true',
'cancelImg': 'img/cancel.png',
'fileDesc': 'jpg/jpeg',
'displayData': 'percentage',
'fileExt': "*.jpg;*.jpeg",
'sizeLimit' : '8388608',
'fileDataName' : 'file',
onComplete: function(event, queueID, fileObj, reposnse, data) {
$('#filesUploaded').append('<a href='+fileObj.filePath+'>'+fileObj.name+'</a><br>');
$("#firstUpload").remove();
}
}); });
</script>

