在某个html元素中设置你想显示的html代码,大家已经很熟悉了。js就有.InnerHTML可以设置。
但是在这个元素后追加html代码也是可以的,这是在jquery手册上找到的
$("button").click(function(){ $("p").after("<p>Hello world!</p>"); });
定义和用法 after() 方法在被选元素后插入指定的内容。 语法 $(selector).after(content) 参数 描述 content 必需。规定要插入的内容(可包含 HTML 标签)。 使用函数来插入内容 使用函数在被选元素之后插入指定的内容。 语法 $(selector).after(function(index)) 亲自试一试 参数 描述 function(index) 必需。规定返回待插入内容的函数。 index - 可选。接收选择器的 index 位置。
<html> <head> <script type="text/javascript" src="/jquery/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("p").after(function(n){ return "<p>The p element above has index " + n + "</p>"; }); }); }); </script> </head> <body> <h1>This is a heading</h1> <p>This is a paragraph.</p> <p>This is another paragraph.</p> <button>在每个 p 元素后插入内容</button> </body> </html>
我的例子:
var jiang=$(":input[name='editVo.string(lessonId)']");//根据name获取这个元素 jiang.after("<font color='red'>*</font>")//在这个元素后追加html代码