在我问的最后一个问题中,关于警报变量。
可以找到here 。
我修复了它,现在可以使用了。
根据我从最后一个答案中获得的知识,我想要输出 <a> </a>
其中包含变量。
但我无法做到这一点。
我确实尝试了我想到的各种类型的转义。没有任何帮助。
所以我要再次问你们:我怎样才能解决这个问题,正确打印我的变量?
$('<a>'
ID von '' + counter + ''
XPosition '' + containerX + '', YPosition '' + ContainerY '</a>').appendTo($('#textuelledarstellung'));
上下文:
var counter = 0;
$('#divfuerimage').on('click', function (evt) {
counter = counter + 1;
var containerX = evt.pageX - $(this).offset().left,
containerY = evt.pageY - $(this).offset().top;
alert('ID von' + counter + ' XPosition' + containerX + ''
, YPosition' + containerY); //this is working
$('<a>'
ID von '' + counter + ''
XPosition '' + containerX + '', YPosition '' + ContainerY '</a>').appendTo($('#textuelledarstellung'));
//this not
最佳答案
使用 jQuery 创建元素并使用其方法来设置数据。
使用
var htmlText = 'ID von' + counter + ' XPosition' + containerX + ', YPosition' + containerY;
$('<a></a>')
.prop('id', YourId)
.prop('href', Url)
.html(htmlText)
.appendTo($('#textuelledarstellung'));
关于javascript - HTML 作为输出 JQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25605172/