我使用的是jQuery1.10.2,我使用的是Uncaught:$(.).live不是函数。我用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>';
}我是新来的。任何帮助都将不胜感激。提前谢谢。
编辑:-
从下面的函数,我调用关闭函数。请核对以下代码:-
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:未定义
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 : '{}'));
}发布于 2019-10-15 07:10:46
下面的代码解决了我的问题。
/**
* Build jQuery validationcode
*
* @access private
* @param string
* @return string
*/
private function build_script($form_name)
{
$script = '<script>$(document).ready(function() { function pyroforms(){} pyroforms.init = function(){}; new pyroforms(); 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 : '{}'));
}发布于 2019-10-15 05:03:20
live()方法在jQuery版本1.7中被废弃,在版本1.9中被删除。使用on()方法代替。请参阅https://www.w3schools.com/jquery/event_live.asp
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>';
}https://stackoverflow.com/questions/58387506
复制相似问题