Php 在prestashop模块文件中添加jquery内联代码束不起作用
我只是个新手。目前我正在prestashop中创建一个小模块。我想向modulename.php文件添加一些jQuery内联代码。但它在那里不起作用。有人能告诉我如何使用jQuery代码来创建prestashop模块文件吗。任何帮助和建议都是可以接受的。谢谢 我的示例代码如下所示Php 在prestashop模块文件中添加jquery内联代码束不起作用,php,jquery,module,prestashop,Php,Jquery,Module,Prestashop,我只是个新手。目前我正在prestashop中创建一个小模块。我想向modulename.php文件添加一些jQuery内联代码。但它在那里不起作用。有人能告诉我如何使用jQuery代码来创建prestashop模块文件吗。任何帮助和建议都是可以接受的。谢谢 我的示例代码如下所示 public function getContent() { $this->_html = '<h2>'.$this->displayName.'</h2>';
public function getContent() {
$this->_html = '<h2>'.$this->displayName.'</h2>';
if (Tools::isSubmit('submitUpdate')) {
Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.'tablename` SET `function_name`="'.$body_option.'",`height`="'.$height.'",`width`="'.$width.'"');
$this->_displayForm();
return $this->_html;
}
}
private function _displayForm() {
$this->_html .= '
<link rel="stylesheet" href="../modules/modulename/css/store_styles.css" />
<script src="../modules/modulename/js/jquery-1.7.2.min.js" type="text/javascript"></script>';
$this->_html .= '<input type="file" name="file" id="file" multiple/>';
$this->_html .= '
<form method="post" action="'.$_SERVER['REQUEST_URI'].'" id="test">';
$this->_html .= '<div class="clear"></div></div>
<label>'.$this->l('Upload Image').' </label>
<div class="margin-form">';
$this->_html .= '<input type="file" name="file" id="file" multiple/>';
$this->_html .= '</div>';
$this->_html .= '
<div class="margin-form clear"><input type="submit" name="submitUpdate" value="'.$this->l('Save').'" class="button" /></div>
</form>
}
公共函数getContent(){
$this->_html='.$this->displayName'.';
if(工具::isSubmit('submitUpdate')){
Db::getInstance()->Execute('UPDATE`.'Db`.'tablename`SET`function`.'U name`='.$body\'option'.','height`='.$height'.','width`='.$width'.');
$this->_displayForm();
返回$this->\u html;
}
}
私有函数_displayForm(){
$this->\u html.='
';
$this->_html.='';
$this->\u html.='
';
$this->\u html.='
“.$this->l(‘上传图像’)。”
';
$this->_html.='';
$this->_html.='';
$this->\u html.='
}
因此,根据我的要求,当我点击复选框时,这段代码应该可以工作
<script type="text/javascript">
jQuery('input[name="file"]').change(function(){
if(jQuery(this).val() == 'yes'){
jQuery('input[type="file"]').prop('multiple', true);
}else{
jQuery('input[type="file"]').prop('multiple', false);
}
});
</script>
jQuery('input[name=“file”]”)。更改(函数(){
if(jQuery(this).val()=='yes'){
jQuery('input[type=“file”]').prop('multiple',true);
}否则{
jQuery('input[type=“file”]').prop('multiple',false);
}
});
请记住此表单是针对管理员的,我希望在后端使用jQuery代码。我不会使用本地代码,请尝试以下操作:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
是的,我知道jquery不起作用,因为它不是从“./modules/modulename/js/jquery-1.7.2.min.js”加载的,所以我提供了另一种解决方案。但也许我误解了这个问题。你的Firebug对加载的Javascript怎么说?您使用的是什么版本的Prestashop?使用(在PS 1.5.x中)$this->context->controller->addCSS(($this->_path)。'CSS/module.CSS')添加CSS和JS文件更方便代码>语法。也可以将HTML插入到模块模板文件中™ 1.5.4.1版本。Firebug没有显示任何错误,而且js代码也在工作。如果是这样,那么我将尝试一些jsconsole.log()
调试。为了了解真正发生了什么,我没有看到您的代码中有任何明显的错误。另外,HTML5不支持多个属性吗?Prestashop 1.5.x正在XHTML1.1上运行。也许这就是你问题的原因。检查是否支持多个浏览器。