使用javascript在下拉值选择中出现问题 [英] issue in dropdown value selection using javascript
问题描述
我有一个下拉菜单,其价值在前面说:
1
10
2
20
3
30 >
4
40
5
50
然后我实际上在我的页面中进行编辑,所以当一个人点击编辑它应该显示在下拉列表中选择的值,所以我首先绑定下拉列表中的所有值,然后使用这样的jquery行:
Hi,
I am having a dropdown and values in it are say for ex:
1
10
2
20
3
30
4
40
5
50
then i am actually doing edit in my page so whenevr a person clicks on edit it should show the value that was selected in dropdown so for that i am first binding all values in dropdown and then using a jquery line like this:
$("#tbl_ddlcolumnname option:contains("+editColDR+")").attr("selected","selected");
其中tbl_ddlcolumnnam是下拉列表ID和需要选择的值我在变量editColDR中得到它但是.....
主要问题是假设5被选中,并且在此行执行后的编辑期间,它显示50为选中或...如果我在编辑期间选择1 ...则显示为10。 ....
为什么会出现这个问题? :)请帮助!!!
提前感谢你!
where tbl_ddlcolumnnam is dropdown id and that value that needs to be selected i am getting it in the variable editColDR but .....
the main issue is suppose 5 was selected and during edit after this line executes it shows 50 as selected or... if i had selected 1 ... during edit it shows as 10.....
Why is this problem arising? :) please help!!!
thanking u in advance!!
推荐答案
(#tbl_ddlcolumnname选项:contains(+ editColDR +))。attr(selected,selected);
("#tbl_ddlcolumnname option:contains("+editColDR+")").attr("selected","selected");
其中tbl_ddlcolumnnam是下拉列表id和那个需要选择的值我在变量editColDR中得到它但.......
主要问题是假设5被选中并且在编辑期间在此行执行后,它显示50为选中或...如果我选择1 ...在编辑期间它显示为10 .....
为什么是出现这个问题? :)请帮助!!!
提前感谢你!!
where tbl_ddlcolumnnam is dropdown id and that value that needs to be selected i am getting it in the variable editColDR but .....
the main issue is suppose 5 was selected and during edit after this line executes it shows 50 as selected or... if i had selected 1 ... during edit it shows as 10.....
Why is this problem arising? :) please help!!!
thanking u in advance!!
尝试使用值
属性,其中editColDR
将是您的下拉列表的值。
和然后使用这个javascript
Try to bind dropdown withValue
property, whereeditColDR
would be value of your dropdown.
and then use this javascript
( ' #tbl_ddlcolumnname')。val(editColDR)
('#tbl_ddlcolumnname').val(editColDR)
这篇关于使用javascript在下拉值选择中出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!