无法在IE上获得警告弹出窗口.在Firefox,Chrome等中工作正常



当没有文本/空白空间时,我试图获得弹出框块。它在Firefox, Chrome & Safari中运行良好。

请检查下面的代码在我的JavaScript文件-:

function submitQuestion(URL,docId,errorMessage)
{
var question = $('textField').value;
if(!question.blank())
{
var submitForm = $("question-form");
submitForm.action = URL+"docId="+docId+"&question="+encodeURIComponent(question);
//alert(submitForm.action);
submitForm.submit();
}
else
{
alert(errorMessage);
return false;
}
}

以上功能在Firefox,Safari和Chrome中工作良好,因为当文本框中没有任何内容(即空/空白)时,它会以弹出窗口的形式出现else &提示errorMessage,但在IE中,它不会以弹出窗口的形式出现else &errorMessage。

请查看下面的代码查看我的预表-:

<form method="POST" id="question-form" onsubmit="return submitQuestion('https://localhost/question-post!input.jspa?','ABC12','Enter your question!');">
                <span class="fieldwrap">
                    <input type="text" placeholder="Ask customers about this document" value="" maxlength="255" autocomplete="off" class="questionInputField" id="textField">
                </span>
                <div class="clear"></div>
                <div id="question-submit" class="widget-div clearfix">
                    <input type="submit" value="Submit question to the portal" class="questionSubmitFormButton">
                    </div>
                </div>  
            </form>

在IE中发生的事情是,当我们没有提供任何文本字段时,它会将占位符作为文本字段的值,即当我们保持文本字段为空或空白时,它会将占位符作为文本字段的值&而不是弹出警告,它会进入if循环,这不应该是case

要使用jQuery访问textField的值,您应该使用val()而不是value。

var question = $('textField').val();
if (question != '') {
 //
}
else {
 //
}

下面是一个工作示例:

<!DOCTYPE html>
<head>
    <title>EXAMPLE</title>
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script>
        function submitQuestion(URL, docId, errorMessage) {
            var question = $('#textField').val();
            if (question.trim() != "") {
                var submitForm = $("#question-form");
                submitForm.attr("action", URL + "docId=" + docId + "&question=" + encodeURIComponent(question));
                return true;
            }
            else {
                alert(errorMessage);
                return false;
            }
        }
    </script>
</head>
<body>
    <form method="POST" id="question-form" onsubmit="return submitQuestion('https://localhost/question-post!input.jspa?','ABC12','Enter your question!');">
        <span class="fieldwrap">
            <input type="text" placeholder="Ask customers about this document" value="" maxlength="255" autocomplete="off" class="questionInputField" id="textField">
        </span>
        <div class="clear"></div>
        <div id="question-submit" class="widget-div clearfix">
            <input type="submit" value="Submit question to the portal" class="questionSubmitFormButton">
        </div>
    </form>
</body>

相关内容

  • 没有找到相关文章

最新更新