Javascript 如何在ODOO10中为按钮单击事件添加java脚本处理程序?
我想使用java脚本为标题中的按钮创建一个处理程序。我的视图模型如下所示:Javascript 如何在ODOO10中为按钮单击事件添加java脚本处理程序?,javascript,openerp,odoo-9,Javascript,Openerp,Odoo 9,我想使用java脚本为标题中的按钮创建一个处理程序。我的视图模型如下所示: <template id="assets_backend" name="petstore" inherit_id="web.assets_backend"> <xpath expr="." position="inside"> <script type="text/javascript" src="/mypetstor
<template id="assets_backend" name="petstore"
inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript"
src="/mypetstore/static/src/js/model_access.js">
</script>
<link href="/mypetstore/static/src/css/petstore.css"
rel="stylesheet">
</link>
</xpath>
</template>
<record model="ir.ui.view" id="my_pet_store_form">
<field name="name">my_pet_store_form</field>
<field name="model">petstore.message</field>
<field name="type">form</field>
<field name="arch" type="xml">
<header>
<button name="click_me" string="Click"
class="oe_highlight"/>
</header>
<form string="Message of the day">
<group col="2">
<group>
<field name="data"/>
</group>
</group>
</form>
</field>
</record>
这就是您的按钮的外观,只需添加onclick,它就是您的处理程序
<header>
<button onclick="myFunction()" name="click_me" string="Click"
class="oe_highlight"/>
</header>
希望有帮助。首先,我建议您为要使用的对象赋予一些ID属性。 像
获取错误:错误:某些模块无法启动我在js文件中添加了此代码并获取错误。我用上面的codeuse$编写了我的js代码,我将JQuery对象重命名为jq。抱歉给您带来不便,jq'click\u me'使用$'click\u me',但是。。它不起作用。。我们需要在模板标签中添加这些按钮吗?获取这个errorjQuery.fn.init{context:document,selector:click_me}它是JavaScript,不是java脚本。
<header>
<button onclick="myFunction()" name="click_me" string="Click"
class="oe_highlight"/>
</header>
<script type = "text/ javascript">
function myFunction() {
alert("Hello! I am an alert box!!");
}
</script>
<button name="click_me" id="click_me" string="Click"
class="oe_highlight"/>
jq('#click_me').bind('click', function(){
alert("hello");
});