我在带有结构的页面上有 2 个表单
<div id="tabs-7">
<form action="/admin/languages" id="1" class="mainForm" method="POST">
<fieldset>
<div class="widget">
<input type="hidden" maxlength="40"class="autoF" name="base" id="base" value="<?php echo base_url(); ?>" />
<input type="hidden" maxlength="40"class="autoF" id="lang_id" name="lang_id" value="1" />
<div class="rowElem">
<label>Calender</label>
<div class="rowElem noborder" >
<label>Date:</label>
<div class="formLeft">
<input type="text" name="date" class="datepicker date" value="<?php echo isset($data['1']['date']['text']) ? $data['1']['date']['text'] : ""; ?>" />
</div>
</div>
<label> Note:</label>
<div class="formLeft">
<?php
if (!empty($data['1']['calender_contents'])) {
$text = preg_replace('/\s+/', ' ', $data['1']['calender_contents']['text']);
}
?>
<textarea name="calender_contents" class="auto limit calender_contents" style="min-width: 600px;max-width: 600px;min-height:80px;max-height: 80px;"><?php echo isset($data['1']['calender_contents']['text']) ? $text : ""; ?></textarea>
</div>
<div class="rowElem "><input type="button" value="Add Note" class="blueBtn left addnote"></div>
</div>
<div class="rowElem "><input type="submit" value="Save" class="greenBtn right"></div>
</div>
</fieldset>
</form>
</div>
<div id="tabs-8">
<form action="/admin/languages" id="2" class="mainForm" method="POST">
<fieldset>
<div class="widget">
<input type="hidden" maxlength="40"class="autoF" name="base" id="base" value="<?php echo base_url(); ?>" />
<input type="hidden" maxlength="40"class="autoF" id="lang_id" name="lang_id" value="2" />
<div class="rowElem">
<label>Calender</label>
<div class="rowElem noborder" >
<label>Date:</label>
<div class="formLeft">
<input type="text" name="date" class="datepicker date" value="<?php echo isset($data['2']['date']['text']) ? $data['2']['date']['text'] : ""; ?>" />
</div>
</div>
<label> Note:</label>
<div class="formLeft">
<?php
if (!empty($data['2']['calender_contents'])) {
$text = preg_replace('/\s+/', ' ', $data['1']['calender_contents']['text']);
}
?>
<textarea name="calender_contents" class="auto limit calender_contents" style="min-width: 600px;max-width: 600px;min-height:80px;max-height: 80px;"><?php echo isset($data['2']['calender_contents']['text']) ? $text : ""; ?></textarea>
</div>
<div class="rowElem "><input type="button" value="Add Note" class="blueBtn left addnote"></div>
</div>
<div class="rowElem "><input type="submit" value="Save" class="greenBtn right"></div>
</div>
</fieldset>
</form>
</div>
和 javascript:
$(".datepicker").datepicker({
defaultDate: +7,
autoSize: true,
appendText: '(yyyy-mm-dd)',
dateFormat: 'yy-mm-dd',
onClose: function(dateText, inst) {
var form = $(this).closest("form");
var formID = $(form).attr("id");
console.log(formID);
if(formID == "1"){
formID = 1;
}
else{
formID = 2;
}
var lang_id = formID;
var date = $(".date").val();
console.log(lang_id);
console.log(date);
$.ajax({
type: 'POST',
url: "/admin/getnote",
dataType: "json",
data: {"date": date, "lang_id": lang_id},
success: function(data) {
console.log(data.arr[0]);
if(data.arr[0] != undefined){
$('.calender_contents').val(data.arr[0].note);
$('.date').val(data.arr[0].date);
}
else {
$('.calender_contents').val("");
}
}
});
}
});
我能够从第一个选项卡中的数据库中获取值,即选项卡 7 很好,但是当使用第二种形式的日期选择器时,它的值也会显示在第一个表中,所以我正在寻找一些建议,因为我可以结合$(this).closest("form");
这些领域
$('.calender_contents').val(data.arr[0].note);
$('.date').val(data.arr[0].date);
这样我就可以在特定的表单字段中获得价值。谢谢你。