我的DOM中有HTML,你可以在下面找到HTML代码。我想写一个javascript函数,它通过id返回图像和字体标签。我该怎么做呢?
<ul id="ChatUsers">
<li class="ajaxchat_Available" id="ajaxchat_42">
<img src="http://cash.co/modules/mod_ajaxchat/images/countryflags/us.gif">
<strong>
<a onclick="javascript:chatWith(42, 'us',) 'darkgreen')" href="javascript:void(0)">
<font color="darkgreen"><b> Admin</b></font>
</a>
</strong>
</li>
<li class="ajaxchat_Available" id="ajaxchat_48"
<img src="http://cash.co/modules/mod_ajaxchat/images/countryflags/xx.gif">
<strong>
<a onclick="javascript:chatWith(48, 'xx', '#ff0000')" href="javascript:void(0)">
<font color="#ff0000"> tony</font>
</a>
</strong>
</li>
</ul>我怎么写函数返回我的img和字体标签的id?
function get_data_by_id(42) {
...
jQuery filter code here...
return {
img: '<img src="http://cash.co/modules/mod_ajaxchat/images/countryflags/us.gif">',
font: '<font color="darkgreen"><b> Admin</b></font>'
}谢谢!
发布于 2013-04-26 17:11:44
试试这个:
function get_data_by_id(id) {
var img = $( "#ajaxchat_" + id ).find( "img" ).get(0);
var font = $( "#ajaxchat_" + id ).find( "font" ).get(0);
return obj = {
"img" : img,
"font" : font
};
}发布于 2013-04-26 17:08:36
假设id是输入参数
var img = $( "#" + id ).find( "img" ).outerHTML();
var font = $( "#" + id ).find( "Strong a font" ).outerHTML();
return obj = {
"img" : img,
"font" : font
};https://stackoverflow.com/questions/16232518
复制相似问题