我有模态窗口和数据属性。
<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>|
这是我的jQuery函数
$('#modalWindow').on('click',function (){
var startDate = new Date($("#StartDate").val());
var endDate = new Date($("#EndDate").val());
var a = $(this).data('additionalinfo');
});
我知道我可以像这样设置这个元素值:
$(this).data('additionalinfo', 'my appended text/value/etc');
我的问题是:如何将文本附加到此属性值,以便我将:
&#34;您确定要提交请求来自&#34; + myAppendedText。
我尝试使用a.val()。append()和a.val()。join()但它没有用。我也检查并尝试了类似how to append text to an attribute like Value之类的东西,但它也没有用。有什么帮助吗?
答案 0 :(得分:2)
数据属性没有附加方法,但您可以像这样使用
var oldData = $(this).data('additionalinfo');
$(this).data('additionalinfo', oldData + " new Text");
答案 1 :(得分:1)
你快到了!
刚刚缓存它现在需要一个新的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.
});