0

I have a form, and when certain inputs are filled another div will display beneath the form. The following is the code:

<form>

<div class="fieldtitle">Full Name:* </div><input type="text" value="" name="fullname" id="fullname" />
<div class="fieldtitle">Email:* </div><input type="text" value="" name="email" id="emailfield" />
<div class="fieldtitle">Contact No:* </div><input type="text" value="" name="contact" id="contact" />

</form>

<div id="demo1" style="width:300px; display:none;"></div>

<script type="text/javascript">

$("#formarea").keyup(function(){
    if($(fullname).val() && $(emailfield).val() && $(contact).val() && $(quantity).val()) {
        $("#demo1").show();
        if($.browser.msie){
           $('#demo1').css({"visibility":"visible"});
        }
    } else {
        $("#demo1").hide();
    }

});

</script>

It is working on all browsers, except for IE - any suggestions as how to solve this?

4

2 回答 2

1

IE 不喜欢建议的 id 或名称选择器,你没有以正确的方式使用它。指定您要定位的选择器。

例如:替换

$(fullname)

$('#fullname')

等等...

顺便说一句,在您的示例代码中看不到任何 ID 为“formarea”的表单。并删除它:if($.browser.msie){...} 它没用。

于 2012-12-11T10:24:55.627 回答
1

html 缺少数量字段,这将导致 Javascript 出现逻辑问题。

<form>
    <div class="fieldtitle">Full Name:* </div><input type="text" value="" name="fullname" id="fullname" />
    <div class="fieldtitle">Email:* </div><input type="text" value="" name="email" id="emailfield" />
    <div class="fieldtitle">Contact No:* </div><input type="text" value="" name="contact" id="contact" />
    <div class="fieldtitle">Quantity:* </div><input type="text" value="" name="quantity" id="quantity" />
</form>

    <div id="demo1" style="width:300px; display:none;">Test</div>

Javascript 将事件绑定到错误的元素。它应该绑定到inputs而不是表单。此外,为每个输入传入的选择器应该是使用 css id 选择器的字符串文字。

$("input").keyup(function(){
    if($("#fullname").val() && $("#emailfield").val() && $("#contact").val() && $("#quantity").val()) {
        $("#demo1").show();
    } else {
        $("#demo1").hide();
    }
});

也不需要 IE 条件。Jquery 的show()/hide()方法是跨浏览器兼容的。示例:http: //jsfiddle.net/DEfVS/1/

于 2012-12-11T10:29:24.377 回答