Javascript 从文本字段获取ID并将其添加到路径

Javascript 从文本字段获取ID并将其添加到路径,javascript,jquery,html,Javascript,Jquery,Html,我使用Roxy Fileman管理CMS中的图像和文件。filemanager有一个自定义选项,可以通过按钮从文本字段插入文件。单击该按钮时,文件管理器将打开。此选项基于文本字段ID。我的问题是我有多个文本字段,因此我使ID:s唯一。但是如何将这些ID添加到路径中的txtFieldId 这是ID为1的第一个文本字段 <input type="text" name="img" id="txtSelectedFile1" class="textfield" > <button cl

我使用Roxy Fileman管理CMS中的图像和文件。filemanager有一个自定义选项,可以通过按钮从文本字段插入文件。单击该按钮时,文件管理器将打开。此选项基于文本字段ID。我的问题是我有多个文本字段,因此我使ID:s唯一。但是如何将这些ID添加到路径中的txtFieldId

这是ID为1的第一个文本字段

<input type="text" name="img" id="txtSelectedFile1" class="textfield" >
<button class="btn btn-default" onclick="openCustomRoxy2()" type="button">Select image</button>

选择图像
第二个ID为2的

<input type="text" name="document" id="txtSelectedFile2" class="textfield" >
<button class="btn btn-default" onclick="openCustomRoxy2()" type="button">Select image</button>

选择图像
下面是带有iframe的div,单击该按钮时会打开filemanager。这就是我需要将ID:s添加到txtFieldId的地方

<div id="roxyCustomPanel2" style="display: none;">
<iframe src="/fileman/index.html?integration=custom&type=files&txtFieldId=txtSelectedFile" style="width:100%;height:100%" frameborder="0">
</iframe>

所以我终于在黑暗势力的帮助下解决了这个问题。与链接中的答案不同的是,我将文本字段中的ID保持不变,并将src函数添加到按钮中

<script>
function go(pth) {
  document.getElementById('roxy').src = pth;
}
</script>

<div id="roxyCustomPanel2" style="display: none;">
  <iframe id="roxy" src="about:blank" style="width:100%;height:100%" frameborder="0"></iframe>
</div>

<input type="text" name="img" id="txtSelectedFile1" class="textfield">
<button class="btn btn-default" onclick="openCustomRoxy2(); go('/fileman/index.html?integration=custom&type=files&txtFieldId=txtSelectedFile1');" type="button">Select image</button>

<input type="text" name="document" id="txtSelectedFile2" class="textfield">
<button class="btn btn-default" onclick="openCustomRoxy2(); go('/fileman/index.html?integration=custom&type=files&txtFieldId=txtSelectedFile2');" type="button">Select image</button>

功能go(pth){
document.getElementById('roxy').src=pth;
}
选择图像
选择图像

我能从您的用例中得到的答案可能是最好的解决方法。它有一个JS解决方案和一个纯html解决方案。我更喜欢JS,因为您不必在每个文件中编写整个src,而且您已经在这样做了,因为您正在使用函数


这个想法似乎不错,但当我尝试时,iframe会打开,但不会加载编辑器。所以我相信src不会加载到函数中。即使我点击了按钮,onselect(我甚至尝试了onclick)会在文本字段上工作吗?你的解决方案看起来不错,但是它可以优化一点,但这不仅仅是一个尝试。