gpt4 book ai didi

jquery - 更新多个html元素的默认值

转载 作者:行者123 更新时间:2023-12-01 03:36:00 24 4
gpt4 key购买 nike

我有一个 html 报告,可以保存到文件并重新打开。
重新打开文件时,有一个“刷新”按钮可以更新数据库中的一些信息。

从视觉上看,它确实引入了新值,但在保存报表并重新打开它时,旧值仍然存在。

保存时我执行以下操作。

function saveDocument(){
var pat_id = $("#pat_id").val();
var doc_id = $("#doc_id").val();
var htmlText = "<html>" + $("html").html() + "</html>";

return $.ajax({
type: "POST",
url: "save.php",
data: { pat_id:pat_id, doc_id:doc_id ,htmlText:htmlText},
success:function(data) {
console.log(data);
if(data == true){
alert("Saved successfully.");
} else {
var msg = "The file failed to save specified location bellow. Please check.\r\n";
var msg = msg + data;
alert(msg);
}
}
});
}

所以我的问题在于第四行

var htmlText = "<html>" + $("html").html() + "</html>";

没有选择刷新中设置的新值。

刷新如下。

    function getRefresh(){
var pat_id = $("#pat_id").val();
var hosp_id = $("#hosp_id").val();
var unit_id = $("#unit_id").val();

$.ajax({
type: "POST",
url: "refresh.php",
data: { pat_id:pat_id,
hosp_id:hosp_id,
unit_id:unit_id
},
success: function(data) {
var json = $.parseJSON(data);

$('#dad').val(json.dad);
$('#dtd').val(json.dtd);
$('#consResp').val(json.consResp);
$('#ddd').val(json.ddd);
$('#disTime').val(json.disTime);
$('#los').val(json.los);
$('#transTo').val(json.transTo);
$('#patName').val(json.patName);
$('#adNo').val(json.adNo);
$('#dob').val(json.dob);
$('#gender').val(json.gender);
$('#weight').val(json.weight);
$('#AddressTop').val(json.AddressTop);
$('#PriDg').val(json.PriDg);
$('#botPICUCons').val(json.botPICUCons);
$('#botSpeCons').val(json.botSpeCons);
$('#gpFullName').val(json.gpFullName);
$('#gpAddressTop').val(json.gpAddressTop);
$('#admFrom').val(json.admFrom);
}
});
}

如果我更改报告中的单个输入,我会按如下方式更新值。

        $("html").on("change","input[type='text'], input[type='date'], input[type='time']", function() {
isDirty = (this.defaultValue !== this.value);
if (isDirty)
this.defaultValue = this.value;
});

但至于“刷新”按钮,我不确定如何将上述操作作为批量分配进行。

这个问题与建议的问题不同,因为我不想更新“这个”。我正在尝试更新 AJAX 成功的大约十几个值。

工作流程

  1. Create html document from DB.
    • It opens with the values as currently reflects in DB.
  2. Now you can Edit the allowed editable fields of the report.
  3. Click save and it saves the Report.
  4. Re-Open the created report from the DB. ( saved html file is called )
  5. Click on "Refresh" to update fields from DB
    • New values where fetched with a AJAX call and now reflect on the opened report in the browser
  6. Click Save.
    • New imported values are not saved, even though they showed up in the report open in the browser.

怀疑旧值可能仍然反射(reflect)在虚拟 DOM 中。因此为什么要这样做

var htmlText = "<html>" + $("html").html() + "</html>";

从虚拟 DOM 获取 html 表示(我怀疑)不会传递要保存的 NEW/REFRESHED 值。

希望这更有意义。

工具栏片段,其中包含用于调用操作的按钮

<div class="no-print">
<div class="buttonBar">
<input type="button" class="button" value="Print" onclick="printMe()">
<input type="button" class="button" value="Save" onclick="getPageHTML()">
<input type="button" class="button" value="Refresh" onclick="getRefresh()">
</div>
</div>

这是 getPageHTML() 代码段

    function getPageHTML() {
saveDocument().then(function(){
alert("Saved successfully.");
window.close();
});
return false;
}

最佳答案

使用.val()设置值实际上不会更新value属性 - 它只会更新 View 中的值。如果需要更新该属性,请手动设置:

.attr("value", val);

关于jquery - 更新多个html元素的默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34530159/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com