如何在Jquery中为变量定义html代码 [英] How to define html code to a variable in Jquery
本文介绍了如何在Jquery中为变量定义html代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
可以帮助我如何将我的html代码定义为jquery变量
i喜欢使用这个html代码来jquery代码
Hi
can one help me how to define my html code to a jquery variable
i like to use this html code to jquery code
<div class="col-md-6" id="newtextbox">
<label>HTS Code:</label>
<button type="button" value="add" class="add" id="add"> <i class="icon-plus-circle2"></i></button>
<div class="input-group">
<span class="input-group-addon">
<input type="checkbox" class="styled" name="input-addon-checkbox" >
</span>
<input type="text" class="form-control" placeholder="35702.03.012">
</div>
</div>
i我们可以看到使用按钮ID的示例代码,他能够动态创建一个复选框和但是我无法获得如何将我的html代码添加到一个变量。我刚刚发布了我的html div代码,如何将整个div分配给变量......?
i have sample code we can see using button id he is able to create dynamically a check box and buton but i am not able to get how to add my html code to a variable. i just posted my html div code above how to assign entire div to a variable...?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Show Popup on Page Load</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<style type="text/css">
body
{
font-family:Gill Sans MT;
padding:10px;
}
fieldset
{
border: solid 1px #000;
padding:10px;
display:block;
clear:both;
margin:5px 0px;
}
legend
{
padding:0px 10px;
background:black;
color:#FFF;
}
input.add
{
float:right;
}
input.fieldname
{
float:left;
display:block;
margin:5px;
}
input.fieldcheck
{
float:left;
display:block;
clear:left;
margin:5px;
margin-top:10px;
}
select.fieldtype
{
float:left;
display:block;
margin:5px;
}
input.remove
{
float:left;
display:block;
margin:5px;
}
#yourform label
{
float:left;
clear:left;
display:block;
margin:5px;
}
#yourform input, #yourform textarea
{
float:left;
display:block;
margin:5px;
}
</style>
<script type='text/javascript'>
$(document).ready(function() {
$("#add").click(function() {
var intId = $("#buildyourform div").length + 1;
var fieldWrapper = $("<div class=\"fieldwrapper\" id=\"field" + intId + "\"/>");
var fchk = $("<input type=\"checkbox\" class=\"fieldcheck\" /> ")
var fName = $("<input type=\"text\" class=\"fieldname\" />");
var removeButton = $("<input type=\"button\" class=\"remove\" value=\"-\" />");
removeButton.click(function() {
$(this).parent().remove();
});
fieldWrapper.append(fchk);
fieldWrapper.append(fName);
fieldWrapper.append(removeButton);
$("#buildyourform").append(fieldWrapper);
});
});
</script>
</head>
<body>
<input type="button" value="Add a field" class="add" id="add" />
</body>
</html>
推荐答案
(document).ready(function(){
(document).ready(function() {
(#add)。click(function(){
var intId =
("#add").click(function() { var intId =
(#buildyourform div)。length + 1;
var fieldWrapper =
("#buildyourform div").length + 1; var fieldWrapper =
这篇关于如何在Jquery中为变量定义html代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文