Javascript 如何使用Jquery将文本附加到数据属性

Javascript 如何使用Jquery将文本附加到数据属性,javascript,jquery,html,Javascript,Jquery,Html,我有模态窗口和数据属性 <a href="#" data-toggle="modal" data-target="#modal-request-confirmation" id="modalWindow" value="Send" class="btn btn-default" data-form="requestPto" data-html="true" **data-additionalinf

我有模态窗口和数据属性

<a href="#"  data-toggle="modal" data-target="#modal-request-confirmation" id="modalWindow" value="Send"
                       class="btn btn-default" data-form="requestPto" data-html="true"
                       **data-additionalinfo="Are you sure you want to submit the request <br /> from"** >
                    Request
                    </a>|
我知道我可以这样设置此元素值:

$(this).data('additionalinfo', 'my appended text/value/etc');
我的问题是:如何将文本附加到此属性值,以便:

“确实要从”+myAppendedText提交请求吗


我尝试了a.val().append()和a.val().join(),但没有成功。我也检查并尝试了类似的东西,但也不起作用。有什么帮助吗?

数据属性没有附加方法,但您可以这样使用

var oldData = $(this).data('additionalinfo');
$(this).data('additionalinfo', oldData + " new Text");

你快到了

只是缓存了它,现在使用一个新的var并再次设置它,如下所示:

$('#modalWindow').on('click',function (){
        var startDate = new Date($("#StartDate").val());
        var endDate = new Date($("#EndDate").val());
        var a = $(this).data('additionalinfo'); // cache it here
        var newA = a + " new Text to put." // add those two
        $(this).data('additionalinfo', newA); // now set it again.
    });

谢谢,我刚做完。您知道以比dateTime.getMonth()+1+dateTime.getDate()+dateTime.getFullYear()更短的格式(MM/dd/yyyy)显示某些日期时间的更短方法吗?
$('#modalWindow').on('click',function (){
        var startDate = new Date($("#StartDate").val());
        var endDate = new Date($("#EndDate").val());
        var a = $(this).data('additionalinfo'); // cache it here
        var newA = a + " new Text to put." // add those two
        $(this).data('additionalinfo', newA); // now set it again.
    });