【问题标题】:Unable to get Alert Pop-Up on IE...Works fine in Firefox,Chrome etc.?无法在 IE 上弹出警报...在 Firefox、Chrome 等中运行良好?
【发布时间】:2013-04-17 05:09:47
【问题描述】:

当没有文本/空格时,我正在尝试获取弹出块。它在 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 &prompt errorMessage 作为弹出窗口,但在 IE 中,它不会转到 else &errorMessage pop -up 永远不会到来。

请检查以下代码以获取我的 forntend 表单-:

<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 循环。

【问题讨论】:

  • 你在什么活动上这样做?不要在提交事件中提交表单 - 请说明您在何处以及如何调用此代码

标签: javascript internet-explorer popup emptydatatext


【解决方案1】:

要使用 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>

【讨论】:

  • 我写过javascript。你能告诉我 javascript,因为 .val() 在点击提交后给了我空白页。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-09-06
  • 1970-01-01
  • 2013-09-27
  • 1970-01-01
  • 1970-01-01
  • 2018-02-04
  • 2019-12-22
相关资源
最近更新 更多