Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 捕获输入字段中的文本更改_Javascript_Jquery_Joomla - Fatal编程技术网

Javascript 捕获输入字段中的文本更改

Javascript 捕获输入字段中的文本更改,javascript,jquery,joomla,Javascript,Jquery,Joomla,我正在使用joomla日历选择日期。下面显示了它的html代码。在这里,当您单击图像时,日历将弹出,您可以在那里选择日期,弹出窗口将关闭,日期值显示在输入文本字段中。我想要的是我想要写一个函数,在日期改变时执行ajax post(输入文本改变)。我尝试了simple alert(),但没有成功。我认为这是由于失去了对文本字段的关注,因为只有我们单击的图像,没有使用鼠标或任何按键与输入字段接触。请帮我解决这个问题 $("#select_date").change(function(){ al

我正在使用joomla日历选择日期。下面显示了它的html代码。在这里,当您单击图像时,日历将弹出,您可以在那里选择日期,弹出窗口将关闭,日期值显示在输入文本字段中。我想要的是我想要写一个函数,在日期改变时执行ajax post(输入文本改变)。我尝试了simple alert(),但没有成功。我认为这是由于失去了对文本字段的关注,因为只有我们单击的图像,没有使用鼠标或任何按键与输入字段接触。请帮我解决这个问题

$("#select_date").change(function(){
   alert('Working');
});
HTML代码

<input id="select_date" type="text" value="2012-02-16" name="select_date" title="Thursday, 16 February 2012">
<img id="select_date_img" class="calendar" alt="Calendar" src="/eap_movies/media/system/images/calendar.png">
JHTML::_('behavior.calendar');
JHTML::calendar(date('Y-m-d'),'select_date', 'select_date', '%Y-%m-%d');

仅当输入焦点不清晰(模糊)时,才会触发更改事件


如果可能的话,您可以监视keypress、keypup或keypdown事件,或者在选择日期时触发自己的事件。

您使用哪个版本的jquery? 我也有同样的问题,我也去了

$('elementName').on("input propertychange",function() {
 alert("detected");
});
因为在您的情况下,使用keyup事件将不起作用,因为实际上没有用户与该字段的交互。

(在/media/system/js/calendar.js下)有一个针对
onSelected
onClose
事件的回调。因此,应该可以捕获日历何时关闭或用户何时选择日期

解决方案1-编辑Joomla

步骤1-您需要覆盖此文件:
libraries/joomla/html/html.php

// added $onSelected parameter
public static function calendar($value, $name, $id, $format = '%Y-%m-%d', $attribs = null, $onSelected)
{
  ...
$document->addScriptDeclaration('window.addEvent(\'domready\', function() {Calendar.setup({
            inputField: "'.$id.'",          // id of the input field
            ifFormat: "'.$format.'",        // format of the input field
            button: "'.$id.'_img",          // trigger for the calendar (button ID)
            align: "Tl",                            // alignment (defaults to "Bl")
            singleClick: true,
            onSelected: '.$onSelected.'
});});');
...
}
步骤2-为onSelected定义回调

JHTML::_('behavior.calendar');
JHTML::calendar(date('Y-m-d'),'select_date', 'select_date', '%Y-%m-%d', null, 'userSelectedDate');
步骤3-实现回调

function userSelectedDate(calendar, date){ ... }
注意:我没有Joomla的活动安装,因此上面的代码可能有语法错误

解决方案2-Sara更简单的解决方案

onchange
定义添加到
JHTML::calendar
$attribs
参数中:

日历(日期('Y-m-d'),'select_date','select_date','select_date','%Y-%m-%d','onchange=“myfunction();”)


也请访问。

日历控件是否有一个回调,您可以在选择日期时使用它?好主意!!!。我没有看到现在我通过html属性完成了它<代码>JHTML::日历(日期('Y-m-d'),'select_date','select_date','%Y-%m-%d','onchange=“myfunction();”)并且它可以工作。这一个肯定更容易:)