[英]Jquery html() instead of val()
I have a select list skinned by a jquery plugin. 我有一个由jquery插件蒙皮的选择列表。 the problem is that when I choose a select element, the value of the select field before post id val() and I want it to be the html() between . 问题是当我选择一个select元素时,select字段的值在post id val()之前,我希望它之间是html()。 but if I put html() instead of val() I get the entire html of the select list optgroup. 但如果我把html()而不是val()我得到选择列表optgroup的整个html。
the part of the jquery where I have problems: 我有问题的jquery的一部分:
$(this).height(selectBoxHeight).change(function(){
selectBoxSpanInner.text($(this).val()).parent().addClass('changed');
});
(here I set the val) and the html: (这里我设置了val)和html:
<select name="123_cat" class ="styled">
<?php foreach($subcategories['categories'] as $sc) { ?>
<optgroup label="<?php echo $sc['name']; ?>">
<?php foreach ($sc['subcategories'] as $ss){?>
<option id = "123_cat[]" value="<?php echo $ss['sid']; ?>" <?php if (isset($_POST['123_cat'])) { if($ss['sid'] == $_POST['123_cat']) echo 'selected = "selected"';} else { if(in_array($ss['sid'], $the_subcategories)) echo 'selected = "selected"'; } ?>><?php echo $ss['name']; ?></option>
<?php }?>
How can I get the text between <option>
</option>
selected onclick instead of the value of it? 如何在<option>
onclick中</option>
<option>
</option>
之间的文本而不是它的值?
你尝试过使用过吗?
$("option:selected", this).text()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.