简体   繁体   English

将jquery-ui Datepicker与单击时插入文本结合起来的方法。

[英]Ways to combine jquery-ui Datepicker with inserting text on click.

I have a table list with many input fields that has the jqueury datpicker in it. 我有一个包含许多输入字段的表列表,其中包含jqueury datpicker。 Every input field has as class datepicker and a random id number. 每个输入字段都有日期选择器类和一个随机ID号。 when clicked in the input field teh datpicker pops up. 在输入字段中单击时,将弹出datpicker。 With a click on he date the dtae gets inserted. 单击日期,将插入dtae。 So the he datepicker works fine. 因此,他的日期选择器工作正常。 But now i want to add an image or text link next to the input field, and when i click on the image/text the content on the input field changes into the selected text. 但是现在我想在输入字段旁边添加图像或文本链接,当我单击图像/文本时,输入字段上的内容将更改为所选文本。 But untill now i cannot combine datepicker and this fucntion into one.... 但是直到现在我还不能将日期选择器和这种功能结合在一起。

example i tried: 我试过的例子:

 <input type="text" id="a11" class="datepicker" name="sterilizationdate_1" value="<?php echo $sterilizationdate_1?>">
    <a href="#" class="CSA" onClick="addTextTag('To sterilization'); return false">CSA</a>

and the javascript 和JavaScript

$('a.CSA').click(function(){
    $('.datepicker').val($('.datepicker').val()+$(this).html());
});

I tested this code without the datepicker and it just works fine... why cant i combine the two? 我在没有datepicker的情况下测试了此代码,但效果很好……为什么我不能将两者结合起来?

FOUND ANOTHER SOLUTION 找到另一个解决方案

custom text insert in datepicker 自定义文本插入日期选择器

You are trying to get the val() of input tag but calling val on anchor tag 您正在尝试获取input标签的val() ,但在anchor标签上调用val

$('a.CSA').click(function(){
    $('.datepicker').val($('.datepicker').prev().val()+$(this).html());
});

Maybe you have another problem on how you call the Datepicker . 在如何调用Datepicker上可能还有另一个问题。

You can try: 你可以试试:

$('a.CSA').on('click', function(){
    $('.datepicker').val($('.datepicker').prev().val()+$(this).html());
});

Instead of: 代替:

$('a.CSA').click(function(){
    $('.datepicker').val($('.datepicker').prev().val()+$(this).html());
});

Please this link .on() 请此链接.on()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM