我正在尝试将HTML代码获取到jquery变量,并且它正在以下代码中工作:
var html_var = $(this).parent().html();
但是,当我想修改“ html_var”时,我做不到,这意味着html代码包含button标记,我需要更改此按钮的值和id吗?我尝试使用“查找”,但我不知道为什么它没有用。
var modified_var = html_var.find('.button').attr('id');
.html()以纯文本形式返回html,因此您可以对父对象进行操作:
var $parent = $(this).parent();
$parent.find.('.button').attr('id', newValue);
或者您可以对文本进行操作
var html_var = $(this).parent().html();
//modify the text
$(this).parent().html(html_var); //replace the parent html with the modified html
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句