I've a textbox with ID something like this
ADF_ADF3_DET0fe90e140MmM10d0%5478
In that ADF_ADF3_DET is fixed, and the rest information is appended and it will be changing. How can I set some value to this text box using jQuery? If the textbox has ADF_ADF3_DET, I need to set? Any ideas?
答案 0 :(得分:1)
Here you go with a solution https://jsfiddle.net/ctqa7s9n/
$('input[id^= ADF_ADF3_DET]').val('1224');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="ADF_ADF3_DET0fe90e140MmM10d0%5478">
Hope this will help you.
答案 1 :(得分:1)
You can select by matching the start of the id like this:
$('[id^="ADF_ADF3_DET"]').doSomeThing(...)
The above will select every element on the page as long as the ID starts with ADF_ADF3_DET.
Another approach would be to add the 'changing data' to a data attribute.
$('#ADF_ADF3_DET').data('attrname', '0fe90e140MmM10d0%5478');
The latest will enable you to select the element with the same css selector, no matter what data is in the data attribute.
答案 2 :(得分:1)
You can use the ^=
selector, this means it will use all the starts with a specific string
$("[id^=ADF_ADF3_DET]").val("yourvalue")
Demo
$("[id^=ADF_ADF3_DET]").val("yourvalue")
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="ADF_ADF3_DET0fe90e140MmM10d0%5478" />
答案 3 :(得分:0)
try with this
// var id = "ADF_ADF3_DET" + $('').val() or value; //your value lik 0fe90e140MmM10d0%5478
var id = "ADF_ADF3_DET" + "0fe90e140MmM10d0%5478";
$('#' + id).val('text'); //done your code