English 中文(简体)
在 j 查询中如何将选项设置为动态选择
原标题:In jQuery how to set an option as selected dynamically

似乎我有一个奇怪的问题。 我将创建一个选择的菜单, 并将其指派给某个名为选中菜单的插件

$( #selectCombo ).selectmenu({style: dropdown });

在指派给它之后, 我无法隐藏它, 或按选择设置选项 。 我尝试了这个

$( <option value= +ret.cId+  selected=true> +ret.cName+ </option> ).appendTo( #selectCombo );   
    $( #selectCombo ).selectmenu({style: dropdown });   

它在工作, 但是它正在显示另一例下方的 dopdown 实例 。 我试图删除类属性, 但是它没有起作用 。 有办法帮助吗 。 plz 帮助 。 @ plz help

最佳回答

Custom 选择菜单 通常会创建 结构的原始 元素,以允许自定义样式 。

这意味着自定义的选定菜单不会知道您对 原始 lt; select> 所做的更改 。

呼叫 .selectmenu( 销毁) 之前先拨打 < code>. selectmenu( { 风格: 下调) ; again.

<强 > e.

var newOption = $( <option value= +ret.cId+  selected=true> +ret.cName+ </option> );
$( #selectCombo ).append(newOption).selectmenu( destroy ).selectmenu({style: dropdown });

http://jsfidd.net/3B3Fp/" rel="notfollow" 举个例子。

问题回答

您可以通过跟随隐藏

$( #selectCombo ).next( .ui-selectmenu .ui-selectmenu-button ).hide();

并设置选定选项使用此选项。

var value = <your value to select>;
$( #selectCombo ).selectmenu("value", value);
var value = "anyvalue";
$("#selectboxid").val("value");

""http://jsfiddle.net/anupam/GGJ7w/" rel="nofollow" > check this





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...