英文:
How can i get id or value from dropify input on clicking the remove button if there is a default value?
问题
<input type="file" name="galleryImages{{ $key }}[]" value="1" data-default-file="{{ asset('storage/services/' . $service->slug . '/gallery/' . $key . '/' . $imageItem) }}" class="dropify" data-id="{{ $key }}">
$(document).ready(function() {
$('.dropify').dropify(); // initializing dropify
// Handling click event on Remove button of dropify
$('.dropify-clear').click(function(e) {
e.preventDefault();
console.log(e.target.value);
alert('Remove Hit'); // Here you can manage your ajax request to delete file from the database.
});
});
英文:
<input type="file" name="galleryImages{{ $key }}\[\]"
value="1"
data-default-file="{{ asset('storage/services/' . $service-\>slug . '/gallery/' . $key . '/' . $imageItem) }}"
class="dropify" data-id="{{ $key }}"
\>
For each input field, I want to get back the value of that clicked input.
$(document).ready(function() {
$('.dropify').dropify(); //initializing dropify
//Handling click event on Remove button of dropify
$('.dropify-clear').click(function(e) {
e.preventDefault();
console.log(e.target.value);
alert('Remove Hit', ); //Here you can manage you ajax request to delete
//file from database.
});
});
答案1
得分: 1
要获取单击删除按钮(dropify-clear按钮)的Dropify输入的ID或值,您可以使用以下代码:
$('.dropify-clear').click(function(e) {
e.preventDefault();
// 获取单击输入的默认值
var defaultValue = $(this).siblings('input[type="file"]').attr('data-default-file');
console.log(defaultValue);
// 获取单击输入的值
var inputValue = $(this).siblings('input[type="file"]').val();
console.log(inputValue);
// 获取单击输入的ID(data-id)
var inputId = $(this).siblings('input[type="file"]').attr('data-id');
console.log(inputId);
alert('Remove Hit'); // 在此处,您可以管理代码以执行任何您想要的操作
});
在上面的代码中,$(this)
引用被单击的删除按钮。我们可以找到相应的Dropify输入元素,并使用.attr('data-default-file')
检索其默认值。同样,可以使用.attr('data-id')
获取输入元素的ID。
请注意,我们不能使用.val()
函数获取dropify输入的默认值,因为默认值放在属性(data-default-file)中。
英文:
To get the ID or value of the Dropify input on clicking the remove button (dropify-clear button), you can use the following code:
$('.dropify-clear').click(function(e) {
e.preventDefault();
// Getting the default value of the clicked input
var defaultValue = $(this).siblings('input[type="file"]').attr('data-default-file');
console.log(defaultValue);
// Getting the value of the clicked input
var inputValue = $(this).siblings('input[type="file"]').val();
console.log(inputValue);
// Getting the ID (data-id) of the clicked input
var inputId = $(this).siblings('input[type="file"]').attr('data-id');
console.log(inputId);
alert('Remove Hit'); // Here you can manage your code to perform anything what you want
});
In the code above, $(this)
refers to the clicked remove button. we can find the corresponding Dropify input element and retrieve its default value using .attr('data-default-file')
. Similarly, the ID of the input element can be obtained using .attr('data-id')
.
Please note that we cann't get the default value of the dropify input by .val()
function because the default value is placed in the attribute (data-default-file)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论