Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/425.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何打印span标记中变量的值?_Javascript_Html_Jsp Tags - Fatal编程技术网

Javascript 如何打印span标记中变量的值?

Javascript 如何打印span标记中变量的值?,javascript,html,jsp-tags,Javascript,Html,Jsp Tags,因此,在这部分代码中,它是一个.jsp文件: if($('accountAddress-table-title').length == 0) { console.log("Adding title accountAddress-table-title"); var spanAccountAddressTableTitle = $("<span id='accountAddress-table-title' style='fo

因此,在这部分代码中,它是一个.jsp文件:

if($('accountAddress-table-title').length == 0) 
{
                console.log("Adding title accountAddress-table-title");
                var spanAccountAddressTableTitle = $("<span id='accountAddress-table-title' style='font-size: 20px;font-weight: bold;margin-left: 10px;'>Opportunity Account </span>");
                $('#accountAddress-table_filter').before(spanAccountAddressTableTitle);
}
请帮助我在Opportunity Account旁边打印accountOracleId的值

结果输出应如下所示:

Opportunity Account (accountOracleId)
使用jQuery

$('#id_name/.class_name').html(value_to_insert);

要将任何文本/html分配给DOM元素,首先需要使用选择器将其作为目标:

$('idOfElement')
$('classOfElement')
用于id-
用于类

要将text/html分配给DOM元素,您需要
.text()
来更改文本,或者
.html()
来更改html

总的来说,它看起来像:

$('#id').text('some text')

然而,在您的情况下,
$(this).data('account-oracleid')
可能是空的。要查看变量的内容,可以使用
console.log
登录到浏览器控制台(通过Firefox上console选项卡-F12下的开发者工具访问)

因此,您目前的完整脚本应类似于:

var id = $(this).data('id');
console.log(id);

$('#mySpan').text('some Text'+ id);

如果console.log返回空值,那么问题在于您的数据标记,而不是您的代码。

如果是span-change
.html
.text
,因为您只是在真正更改。。课文。。还有console.log,看看它是否真的返回了一个值。你能给我一个你所说的例子吗。我会很感激的。肯定的人:)我会尽力的。谢谢:)我会等待你的答复。只需一个说明,你的Opportunity帐户span有
id='accountAddress-table-title'
,但稍后你会使用
$('.'btnAddres label')。html
id
是否不同。我看不到任何具有
id
作为
btnAddres标签的元素。您需要使用
$('#accountAddress table title').html(
instead)看起来问题在于数据tag@ShubhamMishra啊,不用担心:)老实说,我确实认为你的代码应该可以工作,整理好数据标签,你的代码应该可以工作:)@shubhamishra,不用担心,很高兴我能帮上忙:)
var id = $(this).data('id');
console.log(id);

$('#mySpan').text('some Text'+ id);