变量值未附加在h2元素中 [英] variable value is not appending in h2 element
本文介绍了变量值未附加在h2元素中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi, I have variable called "var node = "Hi Mr", Iam trying to append this value on click of a button, im not sure why its not appending.
I tried using html and text, none worked.
JS:
$(function(){
$('.customerResultIndex').on('click',function(){
openCustomerOverlay();
})
});
function openCustomerOverlay(){
var node = "Hi Mr"
$('.customerPopHeading').text(node)
var overlayContainer =
'<div class="customerOverlayShadow">'+
'<div class="customerOverlay borderRadius10px">'+
'<h2 class="customerPopHeading">-- </h2>'+
推荐答案
您不能附加这样的值,而是可以通过以下方式进行连接:
You cannot append a value like this instead you can concatenate it this way:
'<h2 class="customerPopHeading">--'+ node +'</h2>'+
或者您可以移动此行:
$('.customerPopHeading').text(node);
在此下方:
$("body").prepend(overlayContainer).focus();
$('.customerPopHeading').text(node);
小提琴
该元素必须可用于创建jQuery选择器,此处仅当您将其添加在主体中时,才可以在其中添加所需的文本.
Fiddle
The element has to be available to make a jQuery selector, here when you prepend in body only then it is available to put the desired text in it.
这篇关于变量值未附加在h2元素中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文