我想,在失去对 <input>
的关注后字段,对此字段的值执行一些操作,包括更改内容本身(使其变为大写)
如下code :
HTML
<input id="name" type="text"></input>
<div id="upper"></div>
JavaScript + jQuery
$("#name")
.focusout(function() {
// get the text from the form which lost focus
name = $("#name").val();
// turn it into uppercase
name = name.toUpperCase();
// update the form and another entry
$("#upper").text(name);
$("#name").text(name);
})
事件被正确捕获并且 <div>
已更新为小写文本。但是,该字段的内容并未更新。
是否可以更新 <input>
的内容离开后字段?
最佳答案
将字段的 text() 更改为 val()
$("#name").val(name);
关于javascript - 如何更新 .focusout() 上的字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39769410/