我有一个 jquery 变量,其中包含用于动态创建复选框的 html 标签。 现在,根据我的需要,我必须在 jquery 的 .html 标签内添加此变量以显示对话框内的复选框。我的 .html 还包含表单标签以在表单内包含复选框代码。
这是我的 variabel,其中包含 html 标签..
var chbx=<input type="checkbox" id="Mumbai" name="Mumbai" value="Mumbai" />Mumbai<br />
<input type="checkbox" id=" Delhi" name=" Delhi" value=" Delhi" /> Delhi<br />\
<input type="checkbox" id=" Bangalore" name=" Bangalore" value=" Bangalore" /> Bangalore<br />
这是我的 .html 标签,其中包含表单 ..
var $dialog = $('<div></div>').html("<form id='myform'>" +chbx+ "</form>")
.dialog({
autoOpen: false,
title: 'Select Sites',
buttons: {
"Submit": function() { $('form#myform').submit();},
"Cancel": function() {$(this).dialog("close");}
}
});
我尝试附加 +chbx+ 之类的变量,但它没有发生并显示空对话框..
最佳答案
HTML :
<div id="myDiv">
<form id="myForm">
</form>
</div>
jQuery :
var chbx='<input type="checkbox" id="Mumbai" name="Mumbai" value="Mumbai" />Mumbai<br /> <input type="checkbox" id=" Delhi" name=" Delhi" value=" Delhi" /> Delhi<br/><input type="checkbox" id=" Bangalore" name=" Bangalore" value=" Bangalore"/>Bangalore<br />';
$("#myDiv form#myForm").html(chbx);
//to insert dynamically created form
$("#myDiv").html("<form id='dynamicForm'>" +chbx + "'</form>");
关于javascript - 如何在 .html 标签内附加一个 jQuery 变量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19680445/