如何将cssclass添加到由javascript创建的动态文本框中 [英] How to add cssclass to dynamic textbox created by javascript

查看:67
本文介绍了如何将cssclass添加到由javascript创建的动态文本框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$("#btnAdd").bind("click", function () {
                 var div = $("<div />");
                 div.html(GetDynamicTextBox("", ""));
                 $('ContactName').addClass('form-control has-ns');
                 
                 $("#TextBoxContainer").append(div);
                 return false;
             });
             $("body").on("click", ".remove", function () {
                 $(this).closest("div").remove();

             });
         });
         function GetDynamicTextBox(valuename, valueemail) {


             return '<input name = "ContactName" type="text" value = "' + valuename + '" /> ' + '<input name = "ContactEmail" type="text" value = "' + valueemail + '" /> ' +
           '<input type="button" value="Remove" class="remove" />'





我的尝试:



$('ContactName')。addClass('form-control has-ns');

到这行我要添加css类但是它的没有显示在我的textbox.please帮助!



What I have tried:

$('ContactName').addClass('form-control has-ns');
to this line i want to add css class but its not showing on my textbox.please help!

推荐答案

#btnAdd)。bind( 点击 function (){
var div =
("#btnAdd").bind("click", function () { var div =


< div />);
div.html(GetDynamicTextBox( ));
("<div />"); div.html(GetDynamicTextBox("", ""));


' ContactName' )。addClass(' form-control has-ns');
('ContactName').addClass('form-control has-ns');


这篇关于如何将cssclass添加到由javascript创建的动态文本框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆