기본적으로 아래 코드에는 10 개의 요소를 만드는 for 루프가 있으며 버튼을 클릭하면 console.logs 다음과 같습니다.
현재 console.log :
Object {objectProperty: "0"}
Object {objectProperty: "1"}
Object {objectProperty: "2"}
Object {objectProperty: "3"}
Object {objectProperty: "4"}
Object {objectProperty: "5"}
Object {objectProperty: "6"}
Object {objectProperty: "7"}
Object {objectProperty: "8"}
Object {objectProperty: "9"}
그러나 객체 속성 이름이의 값이되기를 원 <span>
하므로 요소를 반복 할 때 <span>
값 과 동일한 새 속성 이름을 할당 합니다.
따라서 console.log가 작동한다면 다음과 같이 보일 것입니다.
Object {0: "0"}
Object {1: "1"}
Object {2: "2"}
Object {3: "3"}
Object {4: "4"}
Object {5: "5"}
Object {6: "6"}
Object {7: "7"}
Object {8: "8"}
Object {9: "9"}
내가 지금까지 가지고있는 것 :
$(document).on('change', "select[id*='checkBox']", function(e) {
// Disable or Enable input fields
if (($("option:selected", this).text() === "No")) {
$(this).next().next().attr('readonly', true).addClass('input-disabled');
} else {
$(this).next().next().attr('readonly', false).removeClass('input-disabled');
}
});
$(document).on('click', "#generateButton", function(e) {
// Define associative arrays that will compose licence object
var Signed = new Object();
var NotSigned = new Object();
var Licence = new Object();
// On generate button click, get all values to dynamically create signed and unsigned values
$('.list-group-item').each(function(key, value)
{
var objectProperty = $(this)[0].children[1].innerHTML;
Signed.objectProperty = $(this)[0].children[2].value;
console.log(Signed);
});
});
// Append list-groups on page so that configuration elements can be appended
$("#optionalFieldsRow").children().find('.panel-body').append("<div class='row'><div class='col-sm-6 left'><ul class='list-group'></ul></div><div class='col-sm-6 right'><ul class='list-group'></ul></div></div>");
// Loop through configuration items and display element on page
for (var i = 0; i < 10; i++) {
$("#optionalFieldsRow").children().find('.left').find('.list-group').append("<li class='list-group-item'><select id='checkBox" + i + "' class='optionalFieldsRowCheckBox' name='checkBox" + i + "'><option>Yes</option><option>No</option></select><span class='optionalLabel'>" + i + "</span><input id='input" + i + "' type='text' value='" + i + "' name='input" + i + "'></li>");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<ul class="list-group">
<!-- /.panel-body -->
<div class="pull-right">
<button name="Save configuration button" id="generateButton" class="btn btn-primary">Generate .properties</button>
<!--<button name="Save configuration button" onclick="GenerateLicence(this);" id="generateButton" class="btn btn-primary">Generate .properties</button>-->
</div>
</ul>
</div>
<!-- /.col-lg-12 -->
</div>
<div id="optionalFieldsRow" class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<!-- /.panel-heading -->
<div class="panel-body">
<!-- Optional fields for licences -->
<div class="row">
<!-- /.row -->
</div>
</div>
<!-- /.panel -->
</div>
<!-- /.col-lg-8 -->
</div>
<!-- /.row -->
</div>
<!-- /#page-wrapper -->
</div>
var obj = {};
obj["<new property name>"] = <new property value>;
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다