我有一个函数,用于更新具有特定id的文本字段中的值:
from Tkinter import *
import Tkinter, Tkconstants, tkFileDialog
def askopenfile():
# If you want to browse files.
path_to_file = tkFileDialog.askopenfilename() # for a file
# If you want to browse directories.
path_to_folder = tkFileDialog.askdirectory() # for a directory
print "File: " + path_to_file
print "Folder: " + path_to_folder
root = Tk()
b = Button(root, text="CLICK ME", command=askopenfile)
b.pack()
root.mainloop()
我这样称呼它多次:
function UpdateField(name, val)
{
var fieldId = "pv-" + name;
document.getElementById(fieldId).value = val;
}
问题是前两个字段是空白的,只有最后一个字段(field3)才能获得正确的值。如果我删除了第三个UpdateField("field1", "somevalue");
UpdateField("field2", "othervalue");
UpdateField("field3", "qwerty");
电话,那么field2将是正确的,但第一个将是空白的。
答案 0 :(得分:0)
这是您工作代码的小提琴:
https://jsfiddle.net/qzbxa9qa/
function UpdateField(name, val) {
var fieldId = "pv-" + name;
document.getElementById(fieldId).value = val;
}
UpdateField("field1", "somevalu1e");
UpdateField("field2", "othervalue2");
UpdateField("field3", "qwe3rty");
<input id="pv-field1" />
<input id="pv-field2" />
<input id="pv-field3" />
似乎你的标记中有拼写错误