I am trying to append a text from a button to a modal window.
It works so far, but if the data contains more than 2 word, it just prints the first one what am I doing wrong?
...
<button type="submit" class="observeSubmit deleteProject" data-title={{ $productValue->title }} name="removeProj">
...
Js function:
$('button[name="removeProj"]').on('click', function(e){
var $form = $(this).closest('form'); // closest parent form
e.preventDefault();
$("#prodTitle").empty().append($(this).data('title') || '-');
$('#confirm').modal({ backdrop: 'static', keyboard: false })
$('#delete').click(function() {
$form.trigger('submit'); // submit the form
});
});
So if I click on the button a modal opens and shows the value inside $productValue->title
.
If $productValue->title
holds for example Jon Doe.
The window just shows Jon.
I am not sure if it is due to the data attribute, maybe it can just hold one value, or if it due to the javascript function.
您需要将自定义属性包装在引号中。
<button data-title="{{ $productValue->title }}"></button>
<button type="submit" class="observeSubmit deleteProject" data-title="{{ $productValue->title }}" name="removeProj">
现在,它为数据标题分配值“ Jon”,并将Doe视为单独的属性。
working fine here https://jsfiddle.net/
<form action="">
<button type="submit" class="observeSubmit deleteProject" data-title="test sdfg" name="removeProj">btntest</button>
</form>
<div id="prodTitle"></div>
$('button[name="removeProj"]').on('click', function(e){
var form = $(this).closest('form'); // closest parent form
debugger
e.preventDefault();
$("#prodTitle").empty().append($(this).data('title') || '-');
$('#confirm').modal({ backdrop: 'static', keyboard: false })
$('#delete').click(function() {
$form.trigger('submit'); // submit the form
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.