在一页上使用具有多个表单的日期选择器

发布于 2024-12-19 23:34:46 字数 2865 浏览 0 评论 0原文

我在一页上有 2 个表单,两个表单中都有一个日期字段,可打开日期选择器 javascript。

当我单击第一个表单日期字段时,我选择一个日期并且一切正常。 当我单击第二个表单时,日期选择器会像平常一样弹出,但是当我选择日期时,日期会插入到第一个表单日期字段中。

这是为什么?

Javascript 如下:

<script>
$(function() {
    $('.datepicker').datepicker({
        numberOfMonths: 3,
        showButtonPanel: true
    });
});
</script>

我尝试执行 $('.datepicker', this).datepicker({ 但它不起作用!有什么想法吗?

两种形式的 HTML:

 <form method="post" action="contact.php" name="contactform" id="contactform"      
  class="contactform"><div class="message"></div>
 <div id="my_contact_left">



        <label for="name" accesskey="U"><span class="required">*
 </span>Name</label><br />
        <input name="name" type="text" id="name" size="30" class="name" />

        <br />
        <label for="email" accesskey="E"><span class="required">*
 </span>Email</label><br />
        <input name="email" type="text" id="email" size="30" class="email"

 />

        <br />
        <label for="phone" accesskey="P"><span class="required">*
 </span>Phone:</label><br />
        <input name="phone" type="text" id="phone" size="30" class="phone"
 />

        <br />
        <label for="dayin" accesskey="P">Day in:</label><br />

        <input name="dayin" type="text" id="dayin" size="30" class="dayin 
datepicker" />

        <br />
        <label for="dayout" accesskey="P">Day out:</label><br />
        <input name="dayout" type="text" id="dayout" size="30" 
class="dayout datepicker" />

</div>
<div id="my_contact_right">

        <label for="comments" accesskey="C"><span class="required">*
</span>Your Comments</label><br />
        <textarea name="comments" cols="40" rows="3" id="comments"
class="comments" style="width: 350px; height:100px;"></textarea>

        <p><span class="required">*</span>Type the validation code in 
below</p>

        <div style="width:100px; height:40px; float:left;"><label 
for="verify" accesskey="V">&nbsp;&nbsp;&nbsp;<img src="image.php" alt="Image 
verification" 
border="0"/></label></div>
        <div style="width:310px; height:40px; float:right;"><input  
name="verify" type="text" id="verify" class="verify" size="6" value="" style="width:  
50px;" />
        <input type="submit" style="margin-left:112px;" class="submit"  
id="submit" value="Send it!" /></div>
        <div style="clear:both; width:410px;"></div>

</div>
<div id="clearing1"></div>

        </form>

I have 2 forms on 1 page and a date field in both forms which open up the datepicker javascript.

When I click the first forms date field, I select a date and all works well.
When I click the SECOND form, the datepicker pops up like normal, but when I select a date, the date gets inserted into the first forms date field.

Why is that?

Javascript goes like:

<script>
$(function() {
    $('.datepicker').datepicker({
        numberOfMonths: 3,
        showButtonPanel: true
    });
});
</script>

I tried doing $('.datepicker', this).datepicker({ but it didn't work! Any ideas?

HTML for both forms:

 <form method="post" action="contact.php" name="contactform" id="contactform"      
  class="contactform"><div class="message"></div>
 <div id="my_contact_left">



        <label for="name" accesskey="U"><span class="required">*
 </span>Name</label><br />
        <input name="name" type="text" id="name" size="30" class="name" />

        <br />
        <label for="email" accesskey="E"><span class="required">*
 </span>Email</label><br />
        <input name="email" type="text" id="email" size="30" class="email"

 />

        <br />
        <label for="phone" accesskey="P"><span class="required">*
 </span>Phone:</label><br />
        <input name="phone" type="text" id="phone" size="30" class="phone"
 />

        <br />
        <label for="dayin" accesskey="P">Day in:</label><br />

        <input name="dayin" type="text" id="dayin" size="30" class="dayin 
datepicker" />

        <br />
        <label for="dayout" accesskey="P">Day out:</label><br />
        <input name="dayout" type="text" id="dayout" size="30" 
class="dayout datepicker" />

</div>
<div id="my_contact_right">

        <label for="comments" accesskey="C"><span class="required">*
</span>Your Comments</label><br />
        <textarea name="comments" cols="40" rows="3" id="comments"
class="comments" style="width: 350px; height:100px;"></textarea>

        <p><span class="required">*</span>Type the validation code in 
below</p>

        <div style="width:100px; height:40px; float:left;"><label 
for="verify" accesskey="V">   <img src="image.php" alt="Image 
verification" 
border="0"/></label></div>
        <div style="width:310px; height:40px; float:right;"><input  
name="verify" type="text" id="verify" class="verify" size="6" value="" style="width:  
50px;" />
        <input type="submit" style="margin-left:112px;" class="submit"  
id="submit" value="Send it!" /></div>
        <div style="clear:both; width:410px;"></div>

</div>
<div id="clearing1"></div>

        </form>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁与争疯 2024-12-26 23:34:46
<script>
$(function() {
    $('#datepicker1').datepicker({
        numberOfMonths: 3,
        showButtonPanel: true
    });
   $('#datepicker2').datepicker({
        numberOfMonths: 3,
        showButtonPanel: true
    });
});

</script>

然后为您的日期选择器指定 datepicker1 或 datepicker2 等 id。

<script>
$(function() {
    $('#datepicker1').datepicker({
        numberOfMonths: 3,
        showButtonPanel: true
    });
   $('#datepicker2').datepicker({
        numberOfMonths: 3,
        showButtonPanel: true
    });
});

</script>

Then give your datepickers an id of datepicker1 or datepicker2, etc.

思念满溢 2024-12-26 23:34:46

你可以尝试这样的事情:

//make 2 ids for date pickers instead of class
$(function() {
    $('#datepickerId1, #datePickerId2').datepicker({
        numberOfMonths: 3,
        showButtonPanel: true
    });
});

Can you try something like:

//make 2 ids for date pickers instead of class
$(function() {
    $('#datepickerId1, #datePickerId2').datepicker({
        numberOfMonths: 3,
        showButtonPanel: true
    });
});

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文