$(“#id”)。val()返回dojo.filteringselect对象的选项文本

时间:2013-05-15 13:53:37

标签: javascript jquery html dom dojo

我们有一个dojo过滤选择对象,但必须通过jquery进行验证。现在的问题是

var value= j("#filteringSelectId").val();

值只返回所选选项的文本而不是选定的值...似乎dojo对原始Dom对象进行了一些更改,因为dojo选择对象被标识为input#filteringSelectId.dijitReset

那么如何通过jQuery获取dojo filteringSelect值而不是选项文本呢?它可行吗?

1 个答案:

答案 0 :(得分:2)

如果您查看过滤选择创建的实际HTML,它将看起来像这样(取自dojo's reference docs

<div class="dijit dijitReset dijitInline dijitLeft dijitTextBox dijitComboBox dijitValidationTextBox" id="widget_stateSelect" role="combobox" aria-haspopup="true" data-dojo-attach-point="_popupStateNode" widgetid="stateSelect">
    <div class="dijitReset dijitRight dijitButtonNode dijitArrowButton dijitDownArrowButton dijitArrowButtonContainer" data-dojo-attach-point="_buttonNode" role="presentation" style="">
        <input class="dijitReset dijitInputField dijitArrowButtonInner" value="&#9660; " type="text" tabindex="-1" readonly="readonly" role="button presentation" aria-hidden="true" />
    </div>
    <div class="dijitReset dijitValidationContainer">
        <input class="dijitReset dijitInputField dijitValidationIcon dijitValidationInner" value="&Chi; " type="text" tabindex="-1" readonly="readonly" role="presentation" />
    </div>
    <div class="dijitReset dijitInputField dijitInputContainer">
        <input class="dijitReset dijitInputInner" type="text" autocomplete="off" data-dojo-attach-point="textbox,focusNode" role="textbox" aria-required="true" tabindex="0" id="stateSelect" value="California" />
        <input type="hidden" name="state" value="CA" />
    </div>
</div>

根据这些信息,您可以构建一个选择器,如:

$('#filteringSelectId .dijitReset input[type="hidden"]').val()

如果你只需要在javascript中获取值(我不能说我熟悉jquery验证),你可以做类似的事情

dijit.byId('widgetId').get('value');