本文介绍了如何两次追加相同的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试将相同的变量附加两次,但看来该代码仅适用于第二个变量.
I am trying to append the same variable twice but it appears the code only works on the second one.
var test=document.createElement('option');
test.innerHTML='some data';
$('#data1').append(test);
$('#data2').append(test);
我想两次附加变量测试,而无需创建另一个变量.非常感谢!
I want to append the variable test twice WITHOUT creating another variable. Thanks a lot!
推荐答案
尝试像下面一样放入选择器,
Try putting in same selector like below,
演示: http://jsfiddle.net/mrMva/
$('#data1, #data2').append(test);
这篇关于如何两次追加相同的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!