【发布时间】:2020-02-11 17:04:48
【问题描述】:
我正在使用 jquery 1.10.2 并且遇到 Uncaught TypeError: $(...).live is not a function。我正在使用 Codeigniter 进行 pyrocms 的开发。下面我写了代码:-
public static function close()
{
return '</form><script>$(document).ready(function(){$("a.close").live("click", function(e){ e.preventDefault();$(this).fadeTo(200, 0);$(this).parent().fadeTo(200, 0);$(this).parent().slideUp(400, function(){$(this).remove()})})});</script>';
}
我是新手。任何帮助将不胜感激。提前致谢。
编辑:-
从下面的函数中,我调用了 close 函数。请检查以下代码:-
public static function form($form_name, $output_array=false)
{
if ($output_array)
{
$return = self::get_fields_arrays($form_name);
$return['header'] = self::open($form_name) . $return['header'];
$return['footer'] .= self::close();
} else {
$return = self::open($form_name);
$return .= self::get_fields($form_name);
$return .= self::close();
}
self::$_ci->load->library('jquery_validation');
if ($valid = self::get_validation_array($form_name))
{
self::$_ci->jquery_validation->set_rules($valid);
if (is_array($return))
{
$return['footer'] .= self::$_ci->jquery_validation->run('#frm-'.$form_name);
}
else
{
$return .= self::$_ci->jquery_validation->run('#frm-'.$form_name);
}
}
return $return;
}
从这个标签开始调用它。
<li class="single current parent"><a href="http://php-pc/adina225.dev/hunter-valley-wine-club/wine-club-application">Wine Club Application</a></li>
Jogi Mehul 如果您需要更多帮助,请告诉我。
我已经按照 Jogi 的建议编辑了关闭功能。所以它看起来像下面:-
public static function close()
{
return '</form><script>$(document).ready(function(){$("a.close").on("click", function(e){ e.preventDefault();$(this).fadeTo(200, 0);$(this).parent().fadeTo(200, 0);$(this).parent().slideUp(400, function(){$(this).remove()})})});</script>';
}
现在我遇到以下错误:- Uncaught ReferenceError: pyroforms is not defined
private function build_script($form_name)
{
$script = '<script>$(document).ready(function() { pyroforms.init($("'.$form_name.'"), {submitHandler: function(form) { pyroforms.submit($("'.$form_name.'"), form)}, rules: %s,messages: %s});})</script>';
return sprintf($script, $this->rules, ($this->messages ? $this->messages : '{}'));
}
【问题讨论】:
-
我不知道你的要求是什么。为什么你在控制器而不是视图中编写 jquery?。
-
好吧,我正在使用 pyrocms,所以我必须这样做。
标签: jquery oop codeigniter-3 pyrocms