[英]Change the selected value in a drop down using jQuery and javascript
I have to assign the value in a repeater column in such a way that upon assignment, the value in the repeater column becomes the current selection in the drop down. 我必须在中继器列中分配值,这样分配时,中继器列中的值将成为下拉列表中的当前选择。
I have the correct value to assign in $('#myname_' + rowIndex).text()
, but when I assign this value to the id.value of the dropdown - as shown below - the assignment has no effect. 我可以在
$('#myname_' + rowIndex).text()
分配正确的值,但是当我将此值分配给下拉列表的id.value时(如下所示),分配没有任何效果。 What am I doing wrong. 我究竟做错了什么。
$("ctl00_ContentPlaceHolder1_myname").value = $('#myname_' + rowIndex).text();
jQuery使用val()
,JavaScript(HTML DOM对象)使用value
。
Use: 采用:
$("ctl00_ContentPlaceHolder1_myname").val($('#myname_' + rowIndex).text());
Or 要么
$("ctl00_ContentPlaceHolder1_myname")[0].value = $('#myname_' + rowIndex).text();
Have you tried using the val
function instead? 您是否尝试过使用
val
函数?
$("#ctl00_ContentPlaceHolder1_myname").val($('#myname_' + rowIndex).text());
The val
function can be used to get the value from the object if you use it without parameters 如果不带参数使用
val
函数,则可以使用该函数从对象获取值
$("ctl00_ContentPlaceHolder1_myname").val($('#myname_' + rowIndex).text())
要么
$("ctl00_ContentPlaceHolder1_myname")[0].value = $('#myname_' + rowIndex).text()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.