使用动态ID选择更改后插入输入文本 [英] Insert Input Text After Select Change With Dynamic IDs
问题描述
过去两天,我一直在这里寻找答案,但是似乎没有任何问题.
I've been looking for an answer to this here for the past two days, but nothing seems to stick.
我有一种表单,可以动态创建带有ID的输入,这些ID基本上由参数名称和每个员工的ID通过php组成.
I have a form that dynamically creates inputs with ids basically made up of the param name and each employee's ID through php.
更改持续时间选择后,我想在文本输入字段中插入日期字符串.该页面将导入jquery-1.12.4.js.
I want to insert a date string in a text input field once the duration select is changed. The page imports jquery-1.12.4.js.
这是我得到的最接近的值...没有错误,但是什么也没发生. 在这里拨弄
This is the closest I've gotten ... no errors, but nothing happens. fiddle here
<td width="200px">
<select name="1-duration" id="duration-1">
<option value="">Select</option>
<option value=".5">.5 hr</option>
<option value="1">1 hr</option>
<option value="1.5">1.5 hrs</option>
<option value="2">2 hrs</option>
<option value="2.5">2.5 hrs</option>
<option value="3">3 hrs</option>
<option value="3.5">3.5 hrs</option>
<option value="4">4 hrs</option>
</select>
</td>
<td width="200px"><input type="text" name="1-promDate" value="" id="promDate-1">
<script type="text/javascript">
var employeeID = "1";
var selectID = "duration-" + employeeID;
var textID = "promDate-" + employeeID;
var displayDate = "04/08/2017";
$("#selectID").change(function(){
$("#textID").val('displayDate');
});
</script>
</td>
推荐答案
玩小提琴,将js更改为
Played with the fiddle, changing the js to
var employeeID = "1";
var selectID = "#duration-" + employeeID;
var textID = "#promDate-" + employeeID;
var displayDate = "04/08/2017";
$(selectID).change(function(){
$(textID).val(displayDate);
});
现在它可以在小提琴中工作,但不适用于我的形式.我正在以这种形式为日期选择器导入jquery-1.12.4.js和1.12.1/jquery-ui.js.可以解释断开连接的原因吗?
Now it works in the fiddle, but not in my form. I am importing jquery-1.12.4.js and 1.12.1/jquery-ui.js for a datepicker in this form. Could that explain the disconnect?
这篇关于使用动态ID选择更改后插入输入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!