1

我正在尝试获取微调器的值并显示其值。这是微调器代码:

<div id="site_content">
    <div id="content">
        <h:body>
            <h:form>
                <div class="whiteSpace" />
                <p:spinner id="minutes" min="0" max="1000" value="#{printerSettings.t}" size="1">
                    <p:ajax update="NewTime" />
                    <f:validateLongRange minimum="1" maximum="1000" />
                </p:spinner>
                <h:message id="minutes2" for="minutes" style="color:red" />

这是当用户按下提交时调用的javascript代码

function Thankyou() {
    var minuteVal = $('minutes').val(); //not finding the minutes selected
    alert(minuteVal);
    alert("Sent to the printing holding queue, you may close this app now or carry on using this app, your work will still print out ");
    //location.href = 'index.xhtml';
}

我努力了

var minuteVal = $('minutes').text();

这将返回一个空框。谢谢。

编辑

找到上面的JavaScript

                </h:form>
            </h:body>
        </div>
    </div>
    <script type="text/javascript">
        .....
    </script>
</html>

在 XHTML 的底部。

编辑

这是来源,我不知道这意味着什么

In how many minutes time would you like to have your job sent to the printer ?
<div class="whiteSpace"></div>
<span id="j_idt8:minutes" class="ui-spinner ui-widget ui-corner-all">
    <input id="j_idt8:minutes_input" name="j_idt8:minutes_input" type="text" class="ui-spinner-input ui-inputfield ui-state-default ui-corner-all" autocomplete="off" value="1" size="1" />
    <a class="ui-spinner-button ui-spinner-up ui-corner-tr ui-button ui-widget ui-state-default ui-button-text-only">
        <span class="ui-button-text">
            <span class="ui-icon ui-icon-triangle-1-n"></span>
        </span>
    </a>
    <a class="ui-spinner-button ui-spinner-down ui-corner-br ui-button ui-widget ui-state-default ui-button-text-only">
        <span class="ui-button-text">
            <span class="ui-icon ui-icon-triangle-1-s"></span>
        </span>
    </a>
</span>
<script id="j_idt8:minutes_s" type="text/javascript">
    PrimeFaces.cw('Spinner', 'widget_j_idt8_minutes', {
        id: 'j_idt8:minutes',
        step: 1.0,
        min: 0.0,
        max: 1000.0,
        behaviors: {
            change: function(event) {
                PrimeFaces.ab({
                    source: 'j_idt8:minutes',
                    event: 'valueChange',
                    process: 'j_idt8:minutes',
                    update: 'j_idt8:NewTime'
                }, arguments[1]);
            }
        }
    });
</script>
<span id="j_idt8:minutes2"></span>

编辑

function Thankyou()
{
    var minutesVal = $('#minutes').spinner('value');//not finding the minutes selected
    alert(minutesVal);
    alert("Sent to the printing holding queue, you may close this app now or carry on using this app, your work will still print out ");
    //location.href = 'index.xhtml';
}

现在什么也没有发生,鼠标上的加载符号出现但没有消息框等

4

3 回答 3

4

选择器'minutes'查找带有标签 name 的元素'minutes',如<minutes>。你想通过 id 去,那就是'#minutes'.

var minuteVal = $('#minutes').val();
于 2013-04-20T22:42:20.497 回答
3

jQuery 基于 css 样式的选择器选择元素;例如,您当前拥有的是选择“分钟”标签,您需要的是:

 var minuteVal = $('#minutes').attr("value");

最重要的是,除了,和标签之外,value不是任何东西的有效属性,因此您需要为非标准 html 属性使用前缀属性, with或执行类似于上述的操作。inputtextareaselectdata-.data("value")

于 2013-04-20T22:41:54.380 回答
2

从 HTML 的最终源代码中获取第一个和第二个微调器:

var firstSpinner, secondSpinner;
$('input.ui-spinner-input').each(function(index) {
    if(index == 0) {firstSpinner = $(this).val();}
    else if (index == 1) {secondSpinner = $(this).val();} 
});
alert('First spinner: ' + firstSpinner + ' Second spinner: ' + secondSpinner);
于 2013-04-20T23:09:13.813 回答