jQuery选择器 简单实现<input>标签 增加 删除

来源:互联网 发布:js qq客服代码 编辑:程序博客网 时间:2024/06/06 16:39

前端html代码

    <div id="divOne" class="item">
        <dl>
            <dt>接口信息</dt>
            <dd>接口名称:<input type="text" th:value="${interfaceFormMap.interfaceName}" name="interfaceFormMap.interfaceName" readonly="readonly"/></dd>
            <dd>访问ip:<input type="text" placeholder="请输入访问ip" id="accessIp"/><span onclick="addOne()">+</span></dd>
         </dl>
    </div>



JS代码

function addOne(){

    var str = "<dd>访问ip:<input type='text' placeholder='请输入访问ip' id='accessIp'/><span onclick='remove(this)'>-</span></dd>";
    $("#divOne > dl").append(str);
}
function remove(attr){
    $($(attr).parents("dd")[0]).remove();
}
0 0
原创粉丝点击