innerHTML修改的文本将不会保持可见 [英] Text modified by innerHTML won't stay visible

查看:104
本文介绍了innerHTML修改的文本将不会保持可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数,如果符合条件,它应该在P元素中显示一条消息。该函数运行正常,但是当您按下按钮然后消失时,发送到'output1'的文本会短暂出现。我已经尝试将JS放在头部和身体中,但它似乎没有任何区别。有任何想法吗?谢谢。

I have a function that is supposed to display a message in a P element if conditions are met. The function runs fine but the text that is sent to 'output1' appears briefly when you press the button and then disappears. I have tried putting the JS in the head and in the body but it doesn't seem to make a difference. Any ideas? Thanks.

HTML:

<p id="output1"><p>

Javascript:

Javascript:

<script>
function logicProcess() {
    // alert('function launched');
    if(document.getElementById('q1Y').checked || document.getElementById('q2Y').checked || document.getElementById('q3Y').checked) {
        document.getElementById("output1").innerHTML = "Sorry, you don't qualify for our shared ownership properties";
        }
    else {
        document.getElementById("output1").innerHTML = "You may qualify for our shared ownership scheme. Please complete the registration form.";
        }
}       
</script>


推荐答案

innerHTML不能保持可见的原因是因为那里是一种重置表单的onclick方法。如果是这样,请编辑你的onclick方法,如下所示:

The reason the innerHTML is not staying visible is because there is some type of onclick method that is resetting the form. If that is true edit your onclick method like so:

onClick="function();return false;"

这里的变化是; return false;

The change in here is the ;return false;

这篇关于innerHTML修改的文本将不会保持可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆